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

Side by Side Diff: chrome/browser/chromeos/views/menu_locator.cc

Issue 6250123: WebUI: Change DOMUI to WebUI in two chromeos classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/views/menu_locator.h" 5 #include "chrome/browser/chromeos/views/menu_locator.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/chromeos/views/domui_menu_widget.h" 9 #include "chrome/browser/chromeos/views/webui_menu_widget.h"
10 #include "gfx/point.h" 10 #include "gfx/point.h"
11 #include "gfx/rect.h" 11 #include "gfx/rect.h"
12 #include "gfx/insets.h" 12 #include "gfx/insets.h"
13 #include "views/screen.h" 13 #include "views/screen.h"
14 #include "views/widget/widget.h" 14 #include "views/widget/widget.h"
15 15
16 namespace { 16 namespace {
17 17
18 using chromeos::DOMUIMenuWidget; 18 using chromeos::WebUIMenuWidget;
19 19
20 // Menu's corner radious. 20 // Menu's corner radious.
21 const int kMenuCornerRadius = 0; // crosbug.com/7718. 21 const int kMenuCornerRadius = 0; // crosbug.com/7718.
22 const int kSubmenuOverlapPx = 1; 22 const int kSubmenuOverlapPx = 1;
23 23
24 gfx::Rect GetBoundsOf(const views::Widget* widget) { 24 gfx::Rect GetBoundsOf(const views::Widget* widget) {
25 gfx::Rect bounds; 25 gfx::Rect bounds;
26 widget->GetBounds(&bounds, false); 26 widget->GetBounds(&bounds, false);
27 return bounds; 27 return bounds;
28 } 28 }
29 29
30 // Returns the Rect of the screen that contains the point (x, y). 30 // Returns the Rect of the screen that contains the point (x, y).
31 gfx::Rect GetScreenRectAt(int x, int y) { 31 gfx::Rect GetScreenRectAt(int x, int y) {
32 return views::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); 32 return views::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
33 } 33 }
34 34
35 // Returns adjusted height of the menu that fits to the screen's 35 // Returns adjusted height of the menu that fits to the screen's
36 // hight, and enables scrolling if necessary. 36 // hight, and enables scrolling if necessary.
Avi (use Gerrit) 2011/02/03 15:09:05 fix spelling of height
tfarina 2011/02/03 16:37:49 Done.
37 int AdjustHeight(DOMUIMenuWidget* widget, 37 int AdjustHeight(WebUIMenuWidget* widget,
38 int screen_height, 38 int screen_height,
39 int height) { 39 int height) {
40 // TODO(oshima): Locator needs a preferred size so that 40 // TODO(oshima): Locator needs a preferred size so that
41 // 1) we can tell height == screen_rect is the result of 41 // 1) we can tell height == screen_rect is the result of
42 // locator resizing it, or preferred size happens to be 42 // locator resizing it, or preferred size happens to be
43 // same hight of the screen (which is rare). 43 // same hight of the screen (which is rare).
44 // 2) when the menu is moved to place where it has more space, it can 44 // 2) when the menu is moved to place where it has more space, it can
45 // hide the scrollbar again. (which won't happen on chromeos now) 45 // hide the scrollbar again. (which won't happen on chromeos now)
46 if (height >= screen_height) { 46 if (height >= screen_height) {
47 widget->EnableScroll(true); 47 widget->EnableScroll(true);
48 return screen_height; 48 return screen_height;
49 } 49 }
50 widget->EnableScroll(false); 50 widget->EnableScroll(false);
51 return height; 51 return height;
52 } 52 }
53 53
54 // Updates the root menu's bounds to fit to the screen. 54 // Updates the root menu's bounds to fit to the screen.
55 void UpdateRootMenuBounds(DOMUIMenuWidget* widget, 55 void UpdateRootMenuBounds(WebUIMenuWidget* widget,
56 const gfx::Point& origin, 56 const gfx::Point& origin,
57 const gfx::Size& size, 57 const gfx::Size& size,
58 bool align_right) { 58 bool align_right) {
59 gfx::Rect screen_rect = GetScreenRectAt(origin.x(), origin.y()); 59 gfx::Rect screen_rect = GetScreenRectAt(origin.x(), origin.y());
60 int width = std::min(screen_rect.width(), size.width()); 60 int width = std::min(screen_rect.width(), size.width());
61 int height = AdjustHeight(widget, screen_rect.height(), size.height()); 61 int height = AdjustHeight(widget, screen_rect.height(), size.height());
62 62
63 int x = align_right ? origin.x() - width : origin.x(); 63 int x = align_right ? origin.x() - width : origin.x();
64 int y = origin.y(); 64 int y = origin.y();
65 if (x + width > screen_rect.right()) 65 if (x + width > screen_rect.right())
66 x = screen_rect.right() - width; 66 x = screen_rect.right() - width;
67 if (y + height > screen_rect.bottom()) 67 if (y + height > screen_rect.bottom())
68 y = screen_rect.bottom() - height; 68 y = screen_rect.bottom() - height;
69 widget->SetBounds(gfx::Rect(x, y, width, height)); 69 widget->SetBounds(gfx::Rect(x, y, width, height));
70 } 70 }
71 71
72 // MenuLocator for dropdown menu. 72 // MenuLocator for dropdown menu.
73 class DropDownMenuLocator : public chromeos::MenuLocator { 73 class DropDownMenuLocator : public chromeos::MenuLocator {
74 public: 74 public:
75 explicit DropDownMenuLocator(const gfx::Point& origin) 75 explicit DropDownMenuLocator(const gfx::Point& origin)
76 : origin_(origin) { 76 : origin_(origin) {
77 } 77 }
78 78
79 private: 79 private:
80 virtual SubmenuDirection GetSubmenuDirection() const { 80 virtual SubmenuDirection GetSubmenuDirection() const {
81 return DEFAULT; 81 return DEFAULT;
82 } 82 }
83 83
84 virtual void Move(DOMUIMenuWidget* widget) { 84 virtual void Move(WebUIMenuWidget* widget) {
85 // TODO(oshima): 85 // TODO(oshima):
86 // Dropdown Menu has to be shown above the button, which is not currently 86 // Dropdown Menu has to be shown above the button, which is not currently
87 // possible with Menu2. I'll update Menu2 and this code 87 // possible with Menu2. I'll update Menu2 and this code
88 // after beta. 88 // after beta.
89 gfx::Rect bounds; 89 gfx::Rect bounds;
90 widget->GetBounds(&bounds, false); 90 widget->GetBounds(&bounds, false);
91 UpdateRootMenuBounds(widget, origin_, bounds.size(), !base::i18n::IsRTL()); 91 UpdateRootMenuBounds(widget, origin_, bounds.size(), !base::i18n::IsRTL());
92 } 92 }
93 93
94 virtual void SetBounds(DOMUIMenuWidget* widget, const gfx::Size& size) { 94 virtual void SetBounds(WebUIMenuWidget* widget, const gfx::Size& size) {
95 gfx::Size new_size(size); 95 gfx::Size new_size(size);
96 new_size.Enlarge(0, kMenuCornerRadius); 96 new_size.Enlarge(0, kMenuCornerRadius);
97 UpdateRootMenuBounds(widget, origin_, size, !base::i18n::IsRTL()); 97 UpdateRootMenuBounds(widget, origin_, size, !base::i18n::IsRTL());
98 } 98 }
99 99
100 virtual void GetInsets(gfx::Insets* insets) const { 100 virtual void GetInsets(gfx::Insets* insets) const {
101 insets->Set(0, 0, kMenuCornerRadius, 0); 101 insets->Set(0, 0, kMenuCornerRadius, 0);
102 } 102 }
103 103
104 virtual const SkScalar* GetCorners() const { 104 virtual const SkScalar* GetCorners() const {
(...skipping 16 matching lines...) Expand all
121 public: 121 public:
122 explicit ContextMenuLocator(const gfx::Point& origin) 122 explicit ContextMenuLocator(const gfx::Point& origin)
123 : origin_(origin) { 123 : origin_(origin) {
124 } 124 }
125 125
126 private: 126 private:
127 virtual SubmenuDirection GetSubmenuDirection() const { 127 virtual SubmenuDirection GetSubmenuDirection() const {
128 return DEFAULT; 128 return DEFAULT;
129 } 129 }
130 130
131 virtual void Move(DOMUIMenuWidget* widget) { 131 virtual void Move(WebUIMenuWidget* widget) {
132 gfx::Rect bounds; 132 gfx::Rect bounds;
133 widget->GetBounds(&bounds, false); 133 widget->GetBounds(&bounds, false);
134 UpdateRootMenuBounds(widget, origin_, bounds.size(), base::i18n::IsRTL()); 134 UpdateRootMenuBounds(widget, origin_, bounds.size(), base::i18n::IsRTL());
135 } 135 }
136 136
137 virtual void SetBounds(DOMUIMenuWidget* widget, const gfx::Size& size) { 137 virtual void SetBounds(WebUIMenuWidget* widget, const gfx::Size& size) {
138 gfx::Size new_size(size); 138 gfx::Size new_size(size);
139 new_size.Enlarge(0, kMenuCornerRadius * 2); 139 new_size.Enlarge(0, kMenuCornerRadius * 2);
140 UpdateRootMenuBounds(widget, origin_, new_size, base::i18n::IsRTL()); 140 UpdateRootMenuBounds(widget, origin_, new_size, base::i18n::IsRTL());
141 } 141 }
142 142
143 virtual const SkScalar* GetCorners() const { 143 virtual const SkScalar* GetCorners() const {
144 static const SkScalar corners[] = { 144 static const SkScalar corners[] = {
145 kMenuCornerRadius, kMenuCornerRadius, 145 kMenuCornerRadius, kMenuCornerRadius,
146 kMenuCornerRadius, kMenuCornerRadius, 146 kMenuCornerRadius, kMenuCornerRadius,
147 kMenuCornerRadius, kMenuCornerRadius, 147 kMenuCornerRadius, kMenuCornerRadius,
148 kMenuCornerRadius, kMenuCornerRadius, 148 kMenuCornerRadius, kMenuCornerRadius,
149 }; 149 };
150 return corners; 150 return corners;
151 } 151 }
152 152
153 virtual void GetInsets(gfx::Insets* insets) const { 153 virtual void GetInsets(gfx::Insets* insets) const {
154 insets->Set(kMenuCornerRadius, 0, kMenuCornerRadius, 0); 154 insets->Set(kMenuCornerRadius, 0, kMenuCornerRadius, 0);
155 } 155 }
156 156
157 gfx::Point origin_; 157 gfx::Point origin_;
158 158
159 DISALLOW_COPY_AND_ASSIGN(ContextMenuLocator); 159 DISALLOW_COPY_AND_ASSIGN(ContextMenuLocator);
160 }; 160 };
161 161
162 // MenuLocator for submenu. 162 // MenuLocator for submenu.
163 class SubMenuLocator : public chromeos::MenuLocator { 163 class SubMenuLocator : public chromeos::MenuLocator {
164 public: 164 public:
165 SubMenuLocator(const DOMUIMenuWidget* parent, 165 SubMenuLocator(const WebUIMenuWidget* parent,
166 MenuLocator::SubmenuDirection parent_direction, 166 MenuLocator::SubmenuDirection parent_direction,
167 int y) 167 int y)
168 : parent_rect_(GetBoundsOf(parent)), 168 : parent_rect_(GetBoundsOf(parent)),
169 parent_direction_(parent_direction), 169 parent_direction_(parent_direction),
170 root_y_(parent_rect_.y() + y), 170 root_y_(parent_rect_.y() + y),
171 corners_(NULL), 171 corners_(NULL),
172 direction_(DEFAULT) { 172 direction_(DEFAULT) {
173 } 173 }
174 174
175 private: 175 private:
176 virtual SubmenuDirection GetSubmenuDirection() const { 176 virtual SubmenuDirection GetSubmenuDirection() const {
177 return direction_; 177 return direction_;
178 } 178 }
179 179
180 virtual void Move(DOMUIMenuWidget* widget) { 180 virtual void Move(WebUIMenuWidget* widget) {
181 gfx::Rect bounds; 181 gfx::Rect bounds;
182 widget->GetBounds(&bounds, false); 182 widget->GetBounds(&bounds, false);
183 UpdateBounds(widget, bounds.size()); 183 UpdateBounds(widget, bounds.size());
184 } 184 }
185 185
186 virtual void SetBounds(DOMUIMenuWidget* widget, const gfx::Size& size) { 186 virtual void SetBounds(WebUIMenuWidget* widget, const gfx::Size& size) {
187 gfx::Size new_size(size); 187 gfx::Size new_size(size);
188 new_size.Enlarge(0, kMenuCornerRadius * 2); 188 new_size.Enlarge(0, kMenuCornerRadius * 2);
189 UpdateBounds(widget, new_size); 189 UpdateBounds(widget, new_size);
190 } 190 }
191 191
192 virtual const SkScalar* GetCorners() const { 192 virtual const SkScalar* GetCorners() const {
193 return corners_; 193 return corners_;
194 } 194 }
195 195
196 virtual void GetInsets(gfx::Insets* insets) const { 196 virtual void GetInsets(gfx::Insets* insets) const {
197 insets->Set(kMenuCornerRadius, 0, kMenuCornerRadius, 0); 197 insets->Set(kMenuCornerRadius, 0, kMenuCornerRadius, 0);
198 } 198 }
199 199
200 // Rounded corner definitions for right/left attached submenu. 200 // Rounded corner definitions for right/left attached submenu.
201 static const SkScalar kRightCorners[]; 201 static const SkScalar kRightCorners[];
202 static const SkScalar kLeftCorners[]; 202 static const SkScalar kLeftCorners[];
203 203
204 void UpdateBounds(DOMUIMenuWidget* widget, const gfx::Size& size) { 204 void UpdateBounds(WebUIMenuWidget* widget, const gfx::Size& size) {
205 gfx::Rect screen_rect = GetScreenRectAt(parent_rect_.x(), root_y_); 205 gfx::Rect screen_rect = GetScreenRectAt(parent_rect_.x(), root_y_);
206 int width = std::min(screen_rect.width(), size.width()); 206 int width = std::min(screen_rect.width(), size.width());
207 int height = AdjustHeight(widget, size.height(), screen_rect.height()); 207 int height = AdjustHeight(widget, size.height(), screen_rect.height());
208 208
209 SubmenuDirection direction = parent_direction_; 209 SubmenuDirection direction = parent_direction_;
210 if (direction == DEFAULT) { 210 if (direction == DEFAULT) {
211 if (base::i18n::IsRTL()) { 211 if (base::i18n::IsRTL()) {
212 direction = LEFT; 212 direction = LEFT;
213 } else { 213 } else {
214 direction = RIGHT; 214 direction = RIGHT;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // static 302 // static
303 MenuLocator* MenuLocator::CreateDropDownMenuLocator(const gfx::Point& p) { 303 MenuLocator* MenuLocator::CreateDropDownMenuLocator(const gfx::Point& p) {
304 return new DropDownMenuLocator(p); 304 return new DropDownMenuLocator(p);
305 } 305 }
306 306
307 MenuLocator* MenuLocator::CreateContextMenuLocator(const gfx::Point& p) { 307 MenuLocator* MenuLocator::CreateContextMenuLocator(const gfx::Point& p) {
308 return new ContextMenuLocator(p); 308 return new ContextMenuLocator(p);
309 } 309 }
310 310
311 MenuLocator* MenuLocator::CreateSubMenuLocator( 311 MenuLocator* MenuLocator::CreateSubMenuLocator(
312 const DOMUIMenuWidget* parent, 312 const WebUIMenuWidget* parent,
313 MenuLocator::SubmenuDirection parent_direction, 313 MenuLocator::SubmenuDirection parent_direction,
314 int y) { 314 int y) {
315 return new SubMenuLocator(parent, parent_direction, y); 315 return new SubMenuLocator(parent, parent_direction, y);
316 } 316 }
317 317
318 } // namespace chromeos 318 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698