diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-15 18:02:30 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-15 18:02:30 +0000 |
commit | 154f8bcac65142d7ae6733204c15ae52cfa320c6 (patch) | |
tree | d7375c1119946c2914ee79ef2c0e8aa195b1fbe9 /chrome/browser/views/about_chrome_view.cc | |
parent | 8144d0cea4e142ff7d7a75c84240a4bb8a7fb3a4 (diff) | |
download | chromium_src-154f8bcac65142d7ae6733204c15ae52cfa320c6.zip chromium_src-154f8bcac65142d7ae6733204c15ae52cfa320c6.tar.gz chromium_src-154f8bcac65142d7ae6733204c15ae52cfa320c6.tar.bz2 |
Convert GetPreferredSize from:
void GetPreferredSize(CSize* out);
to:
gfx::Size GetPreferredSize();
.. and update some other places to use gfx::Size as well.
http://crbug.com/2186
Review URL: http://codereview.chromium.org/7344
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/about_chrome_view.cc')
-rw-r--r-- | chrome/browser/views/about_chrome_view.cc | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc index 2094372..e5a8262 100644 --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -189,62 +189,60 @@ void AboutChromeView::Init() { //////////////////////////////////////////////////////////////////////////////// // AboutChromeView, ChromeViews::View implementation: -void AboutChromeView::GetPreferredSize(CSize *out) { - DCHECK(out); - *out = ChromeViews::Window::GetLocalizedContentsSize( +gfx::Size AboutChromeView::GetPreferredSize() { + gfx::Size prefsize(ChromeViews::Window::GetLocalizedContentsSize( IDS_ABOUT_DIALOG_WIDTH_CHARS, - IDS_ABOUT_DIALOG_HEIGHT_LINES).ToSIZE(); + IDS_ABOUT_DIALOG_HEIGHT_LINES)); // We compute the height of the dialog based on the size of the image (it // would be nice to not hard code this), the text in the about dialog and the // margins around the text. - out->cy += 145 + (kPanelVertMargin * 2); + prefsize.Enlarge(0, 145 + (kPanelVertMargin * 2)); // TODO(beng): Eventually the image should be positioned such that hard- // coding the width isn't necessary. This breaks with fonts // that are large and cause wrapping. - out->cx = 422; + prefsize.set_width(422); + return prefsize; } void AboutChromeView::Layout() { - CSize panel_size; - GetPreferredSize(&panel_size); - - CSize sz; + gfx::Size panel_size = GetPreferredSize(); // Background image for the dialog. - about_dlg_background_->GetPreferredSize(&sz); - int background_image_height = sz.cy; // used to position main text below. - about_dlg_background_->SetBounds(0, 0, sz.cx, sz.cy); + gfx::Size sz = about_dlg_background_->GetPreferredSize(); + // used to position main text below. + int background_image_height = sz.height(); + about_dlg_background_->SetBounds(0, 0, sz.width(), sz.height()); // First label goes to the top left corner. - about_title_label_->GetPreferredSize(&sz); + sz = about_title_label_->GetPreferredSize(); about_title_label_->SetBounds(kPanelHorizMargin, kPanelVertMargin, - sz.cx, sz.cy); + sz.width(), sz.height()); // Then we have the version number right below it. - version_label_->GetPreferredSize(&sz); + sz = version_label_->GetPreferredSize(); version_label_->SetBounds(kPanelHorizMargin, about_title_label_->y() + about_title_label_->height() + kRelatedControlVerticalSpacing, kVersionFieldWidth, - sz.cy); + sz.height()); // For the width of the main text label we want to use up the whole panel // width and remaining height, minus a little margin on each side. int y_pos = background_image_height + kRelatedControlVerticalSpacing; - sz.cx = panel_size.cx - 2 * kPanelHorizMargin; + sz.set_width(panel_size.width() - 2 * kPanelHorizMargin); // Draw the text right below the background image. copyright_label_->SetBounds(kPanelHorizMargin, y_pos, - sz.cx, - sz.cy); + sz.width(), + sz.height()); // Then the main_text_label. main_text_label_->SetBounds(kPanelHorizMargin, copyright_label_->y() + copyright_label_->height(), - sz.cx, + sz.width(), main_text_label_height_); // Position the URLs within the main label. The rects here are calculated when @@ -271,38 +269,39 @@ void AboutChromeView::Layout() { CRect parent_bounds; GetParent()->GetLocalBounds(&parent_bounds, false); - throbber_->GetPreferredSize(&sz); + sz = throbber_->GetPreferredSize(); int throbber_topleft_x = kPanelHorizMargin; - int throbber_topleft_y = parent_bounds.bottom - sz.cy - + int throbber_topleft_y = parent_bounds.bottom - sz.height() - kButtonVEdgeMargin - 3; - throbber_->SetBounds(throbber_topleft_x, throbber_topleft_y, sz.cx, sz.cy); + throbber_->SetBounds(throbber_topleft_x, throbber_topleft_y, + sz.width(), sz.height()); // This image is hidden (see ViewHierarchyChanged) and displayed on demand. - success_indicator_.GetPreferredSize(&sz); + sz = success_indicator_.GetPreferredSize(); success_indicator_.SetBounds(throbber_topleft_x, throbber_topleft_y, - sz.cx, sz.cy); + sz.width(), sz.height()); // This image is hidden (see ViewHierarchyChanged) and displayed on demand. - update_available_indicator_.GetPreferredSize(&sz); + sz = update_available_indicator_.GetPreferredSize(); update_available_indicator_.SetBounds(throbber_topleft_x, throbber_topleft_y, - sz.cx, sz.cy); + sz.width(), sz.height()); // This image is hidden (see ViewHierarchyChanged) and displayed on demand. - timeout_indicator_.GetPreferredSize(&sz); + sz = timeout_indicator_.GetPreferredSize(); timeout_indicator_.SetBounds(throbber_topleft_x, throbber_topleft_y, - sz.cx, sz.cy); + sz.width(), sz.height()); // The update label should be at the bottom of the screen, to the right of // the throbber. We specify width to the end of the dialog because it contains // variable length messages. - update_label_.GetPreferredSize(&sz); + sz = update_label_.GetPreferredSize(); int update_label_x = throbber_->x() + throbber_->width() + kRelatedControlHorizontalSpacing; update_label_.SetHorizontalAlignment(ChromeViews::Label::ALIGN_LEFT); update_label_.SetBounds(update_label_x, throbber_topleft_y + 1, parent_bounds.Width() - update_label_x, - sz.cy); + sz.height()); } @@ -326,7 +325,7 @@ void AboutChromeView::Paint(ChromeCanvas* canvas) { // This struct keeps track of where to write the next word (which x,y // pixel coordinate). This struct is updated after drawing text and checking // if we need to wrap. - CSize position; + gfx::Size position; // Draw the first text chunk and position the Chromium url. DrawTextAndPositionUrl(canvas, main_label_chunk1_, link1, rect1, &position, label_bounds, font); @@ -339,8 +338,8 @@ void AboutChromeView::Paint(ChromeCanvas* canvas) { #if defined(GOOGLE_CHROME_BUILD) // Insert a line break and some whitespace. - position.cx = 0; - position.cy += font.height() + kRelatedControlVerticalSpacing; + position.set_width(0); + position.Enlarge(0, font.height() + kRelatedControlVerticalSpacing); // And now the Terms of Service and position the TOS url. DrawTextAndPositionUrl(canvas, main_label_chunk4_, terms_of_service_url_, @@ -352,14 +351,14 @@ void AboutChromeView::Paint(ChromeCanvas* canvas) { #endif // Save the height so we can set the bounds correctly. - main_text_label_height_ = position.cy + font.height(); + main_text_label_height_ = position.height() + font.height(); } void AboutChromeView::DrawTextAndPositionUrl(ChromeCanvas* canvas, const std::wstring& text, ChromeViews::Link* link, gfx::Rect* rect, - CSize* position, + gfx::Size* position, const gfx::Rect& bounds, const ChromeFont& font) { DCHECK(canvas && link && rect && position); @@ -367,20 +366,20 @@ void AboutChromeView::DrawTextAndPositionUrl(ChromeCanvas* canvas, DrawTextStartingFrom(canvas, text, position, bounds, font); // And then position the link after it. - CSize sz; - link->GetPreferredSize(&sz); - WrapIfWordDoesntFit(sz.cx, font.height(), position, bounds); - *rect = gfx::Rect(position->cx, position->cy, sz.cx, sz.cy); + gfx::Size sz = link->GetPreferredSize(); + WrapIfWordDoesntFit(sz.width(), font.height(), position, bounds); + *rect = gfx::Rect(position->width(), position->height(), sz.width(), + sz.height()); // Going from relative to absolute pixel coordinates again. rect->Offset(bounds.x(), bounds.y()); // And leave some space to draw the link in. - position->cx += sz.cx; + position->Enlarge(sz.width(), 0); } void AboutChromeView::DrawTextStartingFrom(ChromeCanvas* canvas, const std::wstring& text, - CSize* position, + gfx::Size* position, const gfx::Rect& bounds, const ChromeFont& font) { // Iterate through line breaking opportunities (which in English would be @@ -409,28 +408,28 @@ void AboutChromeView::DrawTextStartingFrom(ChromeCanvas* canvas, // Draw the word on the screen (mirrored if RTL locale). canvas->DrawStringInt(word, font, SK_ColorBLACK, main_text_label_->MirroredXCoordinateInsideView( - position->cx + bounds.x()), - position->cy + bounds.y(), + position->width() + bounds.x()), + position->height() + bounds.y(), w, h, flags); if (word.size() > 0 && word[word.size() - 1] == L'\x0a') { // When we come across '\n', we move to the beginning of the next line. - position->cx = 0; - position->cy += font.height(); + position->set_width(0); + position->Enlarge(0, font.height()); } else { // Otherwise, we advance position to the next word. - position->cx += w; + position->Enlarge(w, 0); } } } void AboutChromeView::WrapIfWordDoesntFit(int word_width, int font_height, - CSize* position, + gfx::Size* position, const gfx::Rect& bounds) { - if (position->cx + word_width > bounds.right()) { - position->cx = 0; - position->cy += font_height; + if (position->width() + word_width > bounds.right()) { + position->set_width(0); + position->Enlarge(0, font_height); } } |