int Label::GetHeightForWidth(int w) { if(!is_multi_line_) { return View::GetHeightForWidth(w); } w = std::max(0, w-GetInsets().width()); int h = font_.GetHeight(); gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); return h + GetInsets().height(); }
gfx::Point ImageView::ComputeImageOrigin(const gfx::Size& image_size) const { gfx::Insets insets = GetInsets(); int x; // In order to properly handle alignment of images in RTL locales, we need // to flip the meaning of trailing and leading. For example, if the // horizontal alignment is set to trailing, then we'll use left alignment for // the image instead of right alignment if the UI layout is RTL. Alignment actual_horiz_alignment = horiz_alignment_; if(base::i18n::IsRTL() && (horiz_alignment_!=CENTER)) { actual_horiz_alignment = (horiz_alignment_==LEADING) ? TRAILING : LEADING; } switch(actual_horiz_alignment) { case LEADING: x = insets.left(); break; case TRAILING: x = width() - insets.right() - image_size.width(); break; case CENTER: x = (width() - image_size.width()) / 2; break; default: NOTREACHED(); x = 0; break; } int y; switch(vert_alignment_) { case LEADING: y = insets.top(); break; case TRAILING: y = height() - insets.bottom() - image_size.height(); break; case CENTER: y = (height() - image_size.height()) / 2; break; default: NOTREACHED(); y = 0; break; } return gfx::Point(x, y); }
gfx::Size NativeButton::GetPreferredSize() { if(!native_wrapper_) { return gfx::Size(); } gfx::Size sz = native_wrapper_->GetView()->GetPreferredSize(); // Add in the border size. (Do this before clamping the minimum size in case // that clamping causes an increase in size that would include the borders. gfx::Insets border = GetInsets(); sz.set_width(sz.width() + border.left() + border.right()); sz.set_height(sz.height() + border.top() + border.bottom()); // Clamp the size returned to at least the minimum size. if(!ignore_minimum_size_) { gfx::PlatformFontWin* platform_font = static_cast<gfx::PlatformFontWin*>(font_.platform_font()); sz.set_width(std::max(sz.width(), platform_font->horizontal_dlus_to_pixels(kMinWidthDLUs))); sz.set_height(std::max(sz.height(), platform_font->vertical_dlus_to_pixels(kMinHeightDLUs))); } // GTK returns a meaningful preferred size so that we don't need to adjust // the preferred size as we do on windows. return sz; }
gfx::Rect Label::GetAvailableRect() const { gfx::Rect bounds(gfx::Point(), size()); gfx::Insets insets(GetInsets()); bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); return bounds; }
gfx::Rect Label::GetTextBounds() const { gfx::Rect available_rect(GetAvailableRect()); gfx::Size text_size(GetTextSize()); text_size.set_width(std::min(available_rect.width(), text_size.width())); gfx::Insets insets = GetInsets(); gfx::Point text_origin(insets.left(), insets.top()); switch(horiz_alignment_) { case ALIGN_LEFT: break; case ALIGN_CENTER: // We put any extra margin pixel on the left rather than the right. We // used to do this because measurement on Windows used // GetTextExtentPoint32(), which could report a value one too large on the // right; we now use DrawText(), and who knows if it can also do this. text_origin.Offset((available_rect.width()+1-text_size.width())/2, 0); break; case ALIGN_RIGHT: text_origin.set_x(available_rect.right()-text_size.width()); break; default: NOTREACHED(); break; } text_origin.Offset(0, std::max(0, (available_rect.height()-text_size.height()))/2); return gfx::Rect(text_origin, text_size); }
wxSize StyledTextBox::GetMinSize() const { int width = 0; int height = 0; TextMetrics textMetrics = TextMetrics(const_cast<StyledTextBox*>(this)); int fontHeight = textMetrics.GetFontMetrics().height; width += GetInsets().Width(); height += GetInsets().Height(); height += fontHeight; wxSize userMinSize = StyledWindow::GetMinSize(); return wxSize(std::max(width, userMinSize.GetWidth()), std::max(height, userMinSize.GetHeight())); }
gfx::Size ImageView::GetPreferredSize() { gfx::Insets insets = GetInsets(); if(image_size_set_) { gfx::Size image_size; GetImageSize(&image_size); image_size.Enlarge(insets.width(), insets.height()); return image_size; } return gfx::Size(image_.width()+insets.width(), image_.height()+insets.height()); }
int StyledTextBox::FindCursorIndexFromPoint(int point) { int position = -pimpl->textOffset; wxString currentString = ""; TextMetrics metrics(const_cast<StyledTextBox*>(this)); for (auto c : GetText()) { currentString += c; if (GetInsets().Left() + metrics.GetTextSize(currentString, GetDefinitionBundle().GetFont()).GetWidth() > point) { break; } position += 1; } return position; }
gfx::Size Label::GetPreferredSize() { // Return a size of (0, 0) if the label is not visible and if the // collapse_when_hidden_ flag is set. // TODO(munjal): This logic probably belongs to the View class. But for now, // put it here since putting it in View class means all inheriting classes // need ot respect the collapse_when_hidden_ flag. if(!IsVisible() && collapse_when_hidden_) { return gfx::Size(); } gfx::Size prefsize(GetTextSize()); gfx::Insets insets = GetInsets(); prefsize.Enlarge(insets.width(), insets.height()); return prefsize; }
void Label::SizeToFit(int max_width) { DCHECK(is_multi_line_); std::vector<std::wstring> lines; base::SplitString(text_, L'\n', &lines); int label_width = 0; for(std::vector<std::wstring>::const_iterator iter=lines.begin(); iter!=lines.end(); ++iter) { label_width = std::max(label_width, font_.GetStringWidth(*iter)); } label_width += GetInsets().width(); if(max_width > 0) { label_width = std::min(label_width, max_width); } SetBounds(x(), y(), label_width, 0); SizeToPreferredSize(); }
int Label::GetBaseline() { return GetInsets().top() + font_.GetBaseline(); }
int StyledTextBox::GetTextAreaWidth() { return GetSize().GetWidth() - GetInsets().Width(); }