Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: chrome/views/chrome_menu.cc

Issue 7344: Convert GetPreferredSize from:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/views/chrome_menu.cc
===================================================================
--- chrome/views/chrome_menu.cc (revision 3391)
+++ chrome/views/chrome_menu.cc (working copy)
@@ -25,6 +25,9 @@
#include "chrome/views/root_view.h"
#include "generated_resources.h"
+#undef min
+#undef max
+
// Margins between the top of the item and the label.
static const int kItemTopMargin = 3;
@@ -95,7 +98,7 @@
// Max width of a menu. There does not appear to be an OS value for this, yet
// both IE and FF restrict the max width of a menu.
-static const LONG kMaxMenuWidth = 400;
+static const int kMaxMenuWidth = 400;
// Period of the scroll timer (in milliseconds).
static const int kScrollTimerMS = 30;
@@ -167,11 +170,9 @@
ReleaseDC(NULL, dc);
- CSize pref;
MenuItemView menu_item(NULL);
menu_item.SetTitle(L"blah"); // Text doesn't matter here.
- menu_item.GetPreferredSize(&pref);
- pref_menu_height = pref.cy;
+ pref_menu_height = menu_item.GetPreferredSize().height();
}
namespace {
@@ -279,9 +280,8 @@
pref_height_(pref_menu_height) {
}
- virtual void GetPreferredSize(CSize* out) {
- out->cx = kScrollArrowHeight * 2 - 1;
- out->cy = pref_height_;
+ virtual gfx::Size GetPreferredSize() {
+ return gfx::Size(kScrollArrowHeight * 2 - 1, pref_height_);
}
virtual bool CanDrop(const OSExchangeData& data) {
@@ -367,10 +367,9 @@
View* child = GetContents();
// Convert y to view's coordinates.
y -= child->y();
- CSize pref;
- child->GetPreferredSize(&pref);
+ gfx::Size pref = child->GetPreferredSize();
// Constrain y to make sure we don't show past the bottom of the view.
- y = std::max(0, std::min(static_cast<int>(pref.cy) - this->height(), y));
+ y = std::max(0, std::min(pref.height() - this->height(), y));
child->SetY(-y);
}
@@ -428,34 +427,32 @@
return;
}
- CSize pref;
- scroll_up_button_->GetPreferredSize(&pref);
- scroll_up_button_->SetBounds(x, y, width, pref.cy);
- content_height -= pref.cy;
+ gfx::Size pref = scroll_up_button_->GetPreferredSize();
+ scroll_up_button_->SetBounds(x, y, width, pref.height());
+ content_height -= pref.height();
- const int scroll_view_y = y + pref.cy;
+ const int scroll_view_y = y + pref.height();
- scroll_down_button_->GetPreferredSize(&pref);
- scroll_down_button_->SetBounds(x, height() - pref.cy - insets.top(),
- width, pref.cy);
- content_height -= pref.cy;
+ pref = scroll_down_button_->GetPreferredSize();
+ scroll_down_button_->SetBounds(x, height() - pref.height() - insets.top(),
+ width, pref.height());
+ content_height -= pref.height();
scroll_view_->SetBounds(x, scroll_view_y, width, content_height);
scroll_view_->Layout();
}
virtual void DidChangeBounds(const CRect& previous, const CRect& current) {
- CSize content_pref;
- scroll_view_->GetContents()->GetPreferredSize(&content_pref);
- scroll_up_button_->SetVisible(content_pref.cy > height());
- scroll_down_button_->SetVisible(content_pref.cy > height());
+ gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize();
+ scroll_up_button_->SetVisible(content_pref.height() > height());
+ scroll_down_button_->SetVisible(content_pref.height() > height());
}
- virtual void GetPreferredSize(CSize* out) {
- scroll_view_->GetContents()->GetPreferredSize(out);
+ virtual gfx::Size GetPreferredSize() {
+ gfx::Size prefsize = scroll_view_->GetContents()->GetPreferredSize();
gfx::Insets insets = GetInsets();
- out->cx += insets.width();
- out->cy += insets.height();
+ prefsize.Enlarge(insets.width(), insets.height());
+ return prefsize;
}
private:
@@ -500,9 +497,9 @@
canvas->endPlatformPaint();
}
- void GetPreferredSize(CSize* out) {
- out->cx = 10; // Just in case we're the only item in a menu.
- out->cy = separator_height;
+ gfx::Size GetPreferredSize() {
+ return gfx::Size(10, // Just in case we're the only item in a menu.
+ separator_height);
}
private:
@@ -802,9 +799,7 @@
View* parent = GetParent();
if (!parent)
return;
- CSize pref;
- GetPreferredSize(&pref);
- SetBounds(x(), y(), parent->width(), pref.cy);
+ SetBounds(x(), y(), parent->width(), GetPreferredSize().height());
gfx::Insets insets = GetInsets();
int x = insets.left();
@@ -812,30 +807,26 @@
int menu_item_width = width() - insets.width();
for (int i = 0; i < GetChildViewCount(); ++i) {
View* child = GetChildViewAt(i);
- CSize child_pref_size;
- child->GetPreferredSize(&child_pref_size);
- child->SetBounds(x, y, menu_item_width, child_pref_size.cy);
- y += child_pref_size.cy;
+ gfx::Size child_pref_size = child->GetPreferredSize();
+ child->SetBounds(x, y, menu_item_width, child_pref_size.height());
+ y += child_pref_size.height();
}
}
-void SubmenuView::GetPreferredSize(CSize* out) {
- if (GetChildViewCount() == 0) {
- out->SetSize(0, 0);
- return;
- }
+gfx::Size SubmenuView::GetPreferredSize() {
+ if (GetChildViewCount() == 0)
+ return gfx::Size();
int max_width = 0;
int height = 0;
for (int i = 0; i < GetChildViewCount(); ++i) {
View* child = GetChildViewAt(i);
- CSize child_pref_size;
- child->GetPreferredSize(&child_pref_size);
- max_width = std::max(max_width, static_cast<int>(child_pref_size.cx));
- height += child_pref_size.cy;
+ gfx::Size child_pref_size = child->GetPreferredSize();
+ max_width = std::max(max_width, child_pref_size.width());
+ height += child_pref_size.height();
}
gfx::Insets insets = GetInsets();
- out->SetSize(max_width + insets.width(), height + insets.height());
+ return gfx::Size(max_width + insets.width(), height + insets.height());
}
void SubmenuView::DidChangeBounds(const CRect& previous, const CRect& current) {
@@ -1165,9 +1156,10 @@
Paint(canvas, false);
}
-void MenuItemView::GetPreferredSize(CSize* out) {
- out->cx = font_.GetStringWidth(title_) + label_start + item_right_margin;
- out->cy = font_.height() + kItemBottomMargin + kItemTopMargin;
+gfx::Size MenuItemView::GetPreferredSize() {
+ return gfx::Size(
+ font_.GetStringWidth(title_) + label_start + item_right_margin,
+ font_.height() + kItemBottomMargin + kItemTopMargin);
}
MenuController* MenuItemView::GetMenuController() {
@@ -2415,15 +2407,13 @@
SubmenuView* submenu = item->GetSubmenu();
DCHECK(submenu);
- CSize pref;
- submenu->GetScrollViewContainer()->GetPreferredSize(&pref);
+ gfx::Size pref = submenu->GetScrollViewContainer()->GetPreferredSize();
// Don't let the menu go to wide. This is some where between what IE and FF
// do.
- pref.cx = std::min(pref.cx, kMaxMenuWidth);
+ pref.set_width(std::min(pref.width(), kMaxMenuWidth));
if (!state_.monitor_bounds.IsEmpty())
- pref.cx = std::min(pref.cx,
- static_cast<LONG>(state_.monitor_bounds.width()));
+ pref.set_width(std::min(pref.width(), state_.monitor_bounds.width()));
// Assume we can honor prefer_leading.
*is_leading = prefer_leading;
@@ -2435,21 +2425,21 @@
x = state_.initial_bounds.x();
y = state_.initial_bounds.bottom();
if (state_.anchor == MenuItemView::TOPRIGHT)
- x = x + state_.initial_bounds.width() - pref.cx;
+ x = x + state_.initial_bounds.width() - pref.width();
if (!state_.monitor_bounds.IsEmpty() &&
- y + pref.cy > state_.monitor_bounds.bottom()) {
+ y + pref.height() > state_.monitor_bounds.bottom()) {
// The menu doesn't fit on screen. If the first location is above the
// half way point, show from the mouse location to bottom of screen.
// Otherwise show from the top of the screen to the location of the mouse.
// While odd, this behavior matches IE.
if (y < (state_.monitor_bounds.y() +
state_.monitor_bounds.height() / 2)) {
- pref.cy = std::min(pref.cy,
- static_cast<LONG>(state_.monitor_bounds.bottom() - y));
+ pref.set_height(std::min(pref.height(),
+ state_.monitor_bounds.bottom() - y));
} else {
- pref.cy = std::min(pref.cy, static_cast<LONG>(
+ pref.set_height(std::min(pref.height(),
state_.initial_bounds.y() - state_.monitor_bounds.y()));
- y = state_.initial_bounds.y() - pref.cy;
+ y = state_.initial_bounds.y() - pref.height();
}
}
} else {
@@ -2468,15 +2458,15 @@
if (create_on_the_right) {
x = item_loc.x() + item->width() - kSubmenuHorizontalInset;
if (state_.monitor_bounds.width() != 0 &&
- x + pref.cx > state_.monitor_bounds.right()) {
+ x + pref.width() > state_.monitor_bounds.right()) {
if (layout_is_rtl)
*is_leading = true;
else
*is_leading = false;
- x = item_loc.x() - pref.cx + kSubmenuHorizontalInset;
+ x = item_loc.x() - pref.width() + kSubmenuHorizontalInset;
}
} else {
- x = item_loc.x() - pref.cx + kSubmenuHorizontalInset;
+ x = item_loc.x() - pref.width() + kSubmenuHorizontalInset;
if (state_.monitor_bounds.width() != 0 && x < state_.monitor_bounds.x()) {
if (layout_is_rtl)
*is_leading = false;
@@ -2487,22 +2477,21 @@
}
y = item_loc.y() - kSubmenuBorderSize;
if (state_.monitor_bounds.width() != 0) {
- pref.cy = std::min(pref.cy,
- static_cast<LONG>(state_.monitor_bounds.height()));
- if (y + pref.cy > state_.monitor_bounds.bottom())
- y = state_.monitor_bounds.bottom() - pref.cy;
+ pref.set_height(std::min(pref.height(), state_.monitor_bounds.height()));
+ if (y + pref.height() > state_.monitor_bounds.bottom())
+ y = state_.monitor_bounds.bottom() - pref.height();
if (y < state_.monitor_bounds.y())
y = state_.monitor_bounds.y();
}
}
if (state_.monitor_bounds.width() != 0) {
- if (x + pref.cx > state_.monitor_bounds.right())
- x = state_.monitor_bounds.right() - pref.cx;
+ if (x + pref.width() > state_.monitor_bounds.right())
+ x = state_.monitor_bounds.right() - pref.width();
if (x < state_.monitor_bounds.x())
x = state_.monitor_bounds.x();
}
- return gfx::Rect(x, y, pref.cx, pref.cy);
+ return gfx::Rect(x, y, pref.width(), pref.height());
}
// static

Powered by Google App Engine
This is Rietveld 408576698