OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/views/toolbar/wrench_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 using views::CustomButton; | 68 using views::CustomButton; |
69 using views::ImageButton; | 69 using views::ImageButton; |
70 using views::Label; | 70 using views::Label; |
71 using views::LabelButton; | 71 using views::LabelButton; |
72 using views::MenuConfig; | 72 using views::MenuConfig; |
73 using views::MenuItemView; | 73 using views::MenuItemView; |
74 using views::View; | 74 using views::View; |
75 | 75 |
76 namespace { | 76 namespace { |
77 | 77 |
78 // Horizontal padding on the edges of the buttons. | 78 // Horizontal padding on the edges of the in-menu buttons. |
79 const int kHorizontalPadding = 6; | 79 const int kHorizontalPadding = 15; |
80 // Horizontal padding for a touch enabled menu. | |
81 const int kHorizontalTouchPadding = 15; | |
82 | 80 |
83 // Menu items which have embedded buttons should have this height in pixel. | 81 #if defined(OS_CHROMEOS) |
84 const int kMenuItemContainingButtonsHeight = 43; | 82 // Extra horizontal space to reserve for the fullscreen button. |
| 83 const int kFullscreenPadding = 74; |
| 84 // Padding to left and right of the XX% label. |
| 85 const int kZoomLabelHorizontalPadding = kHorizontalPadding; |
| 86 #else |
| 87 const int kFullscreenPadding = 38; |
| 88 const int kZoomLabelHorizontalPadding = 2; |
| 89 #endif |
85 | 90 |
86 // Returns true if |command_id| identifies a bookmark menu item. | 91 // Returns true if |command_id| identifies a bookmark menu item. |
87 bool IsBookmarkCommand(int command_id) { | 92 bool IsBookmarkCommand(int command_id) { |
88 return command_id >= WrenchMenuModel::kMinBookmarkCommandId && | 93 return command_id >= WrenchMenuModel::kMinBookmarkCommandId && |
89 command_id <= WrenchMenuModel::kMaxBookmarkCommandId; | 94 command_id <= WrenchMenuModel::kMaxBookmarkCommandId; |
90 } | 95 } |
91 | 96 |
92 // Returns true if |command_id| identifies a recent tabs menu item. | 97 // Returns true if |command_id| identifies a recent tabs menu item. |
93 bool IsRecentTabsCommand(int command_id) { | 98 bool IsRecentTabsCommand(int command_id) { |
94 return command_id >= WrenchMenuModel::kMinRecentTabsCommandId && | 99 return command_id >= WrenchMenuModel::kMinRecentTabsCommandId && |
(...skipping 13 matching lines...) Expand all Loading... |
108 gfx::Insets insets = border()->GetInsets(); | 113 gfx::Insets insets = border()->GetInsets(); |
109 pref.Enlarge(insets.width(), insets.height()); | 114 pref.Enlarge(insets.width(), insets.height()); |
110 } | 115 } |
111 return pref; | 116 return pref; |
112 } | 117 } |
113 | 118 |
114 private: | 119 private: |
115 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); | 120 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); |
116 }; | 121 }; |
117 | 122 |
118 // Border for buttons contained in the menu. This is only used for getting the | |
119 // insets, the actual painting is done in InMenuButtonBackground. | |
120 class MenuButtonBorder : public views::Border { | |
121 public: | |
122 MenuButtonBorder(const MenuConfig& config, bool use_new_menu) | |
123 : horizontal_padding_(use_new_menu ? | |
124 kHorizontalTouchPadding : kHorizontalPadding), | |
125 insets_(config.item_top_margin, horizontal_padding_, | |
126 config.item_bottom_margin, horizontal_padding_) { | |
127 } | |
128 | |
129 // Overridden from views::Border. | |
130 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE { | |
131 // Painting of border is done in InMenuButtonBackground. | |
132 } | |
133 | |
134 virtual gfx::Insets GetInsets() const OVERRIDE { | |
135 return insets_; | |
136 } | |
137 | |
138 virtual gfx::Size GetMinimumSize() const OVERRIDE { | |
139 // This size is sufficient for InMenuButtonBackground::Paint() to draw any | |
140 // of the button types. | |
141 return gfx::Size(4, 4); | |
142 } | |
143 | |
144 private: | |
145 // The horizontal padding dependent on the layout. | |
146 const int horizontal_padding_; | |
147 | |
148 const gfx::Insets insets_; | |
149 | |
150 DISALLOW_COPY_AND_ASSIGN(MenuButtonBorder); | |
151 }; | |
152 | |
153 // Combination border/background for the buttons contained in the menu. The | 123 // Combination border/background for the buttons contained in the menu. The |
154 // painting of the border/background is done here as LabelButton does not always | 124 // painting of the border/background is done here as LabelButton does not always |
155 // paint the border. | 125 // paint the border. |
156 class InMenuButtonBackground : public views::Background { | 126 class InMenuButtonBackground : public views::Background { |
157 public: | 127 public: |
158 enum ButtonType { | 128 enum ButtonType { |
159 LEFT_BUTTON, | 129 LEFT_BUTTON, |
160 CENTER_BUTTON, | 130 CENTER_BUTTON, |
161 RIGHT_BUTTON, | 131 RIGHT_BUTTON, |
162 SINGLE_BUTTON, | 132 SINGLE_BUTTON, |
163 }; | 133 }; |
164 | 134 |
165 InMenuButtonBackground(ButtonType type, bool use_new_menu) | 135 explicit InMenuButtonBackground(ButtonType type) |
166 : type_(type), | 136 : type_(type), left_button_(NULL), right_button_(NULL) {} |
167 use_new_menu_(use_new_menu), | |
168 left_button_(NULL), | |
169 right_button_(NULL) {} | |
170 | 137 |
171 // Used when the type is CENTER_BUTTON to determine if the left/right edge | 138 // Used when the type is CENTER_BUTTON to determine if the left/right edge |
172 // needs to be rendered selected. | 139 // needs to be rendered selected. |
173 void SetOtherButtons(const CustomButton* left_button, | 140 void SetOtherButtons(const CustomButton* left_button, |
174 const CustomButton* right_button) { | 141 const CustomButton* right_button) { |
175 if (base::i18n::IsRTL()) { | 142 if (base::i18n::IsRTL()) { |
176 left_button_ = right_button; | 143 left_button_ = right_button; |
177 right_button_ = left_button; | 144 right_button_ = left_button; |
178 } else { | 145 } else { |
179 left_button_ = left_button; | 146 left_button_ = left_button; |
180 right_button_ = right_button; | 147 right_button_ = right_button; |
181 } | 148 } |
182 } | 149 } |
183 | 150 |
184 // Overridden from views::Background. | 151 // Overridden from views::Background. |
185 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { | 152 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { |
186 CustomButton* button = CustomButton::AsCustomButton(view); | 153 CustomButton* button = CustomButton::AsCustomButton(view); |
187 views::Button::ButtonState state = | 154 views::Button::ButtonState state = |
188 button ? button->state() : views::Button::STATE_NORMAL; | 155 button ? button->state() : views::Button::STATE_NORMAL; |
189 int w = view->width(); | |
190 int h = view->height(); | 156 int h = view->height(); |
191 if (use_new_menu_) { | 157 |
192 // Normal buttons get a border drawn on the right side and the rest gets | 158 // Normal buttons get a border drawn on the right side and the rest gets |
193 // filled in. The left button however does not get a line to combine | 159 // filled in. The left button however does not get a line to combine |
194 // buttons. | 160 // buttons. |
195 if (type_ != RIGHT_BUTTON) { | 161 if (type_ != RIGHT_BUTTON) { |
196 canvas->FillRect(gfx::Rect(0, 0, 1, h), | 162 canvas->FillRect(gfx::Rect(0, 0, 1, h), |
197 BorderColor(view, views::Button::STATE_NORMAL)); | 163 BorderColor(view, views::Button::STATE_NORMAL)); |
198 } | |
199 gfx::Rect bounds(view->GetLocalBounds()); | |
200 bounds.set_x(view->GetMirroredXForRect(bounds)); | |
201 DrawBackground(canvas, view, bounds, state); | |
202 return; | |
203 } | 164 } |
204 const SkColor border_color = BorderColor(view, state); | |
205 switch (TypeAdjustedForRTL()) { | |
206 // TODO(pkasting): Why don't all the following use SkPaths with rounded | |
207 // corners? | |
208 case LEFT_BUTTON: | |
209 DrawBackground(canvas, view, gfx::Rect(1, 1, w, h - 2), state); | |
210 canvas->FillRect(gfx::Rect(2, 0, w, 1), border_color); | |
211 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); | |
212 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); | |
213 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); | |
214 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border_color); | |
215 break; | |
216 | 165 |
217 case CENTER_BUTTON: { | 166 gfx::Rect bounds(view->GetLocalBounds()); |
218 DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); | 167 bounds.set_x(view->GetMirroredXForRect(bounds)); |
219 SkColor left_color = state != views::Button::STATE_NORMAL ? | 168 DrawBackground(canvas, view, bounds, state); |
220 border_color : BorderColor(view, left_button_->state()); | |
221 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); | |
222 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border_color); | |
223 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), | |
224 border_color); | |
225 SkColor right_color = state != views::Button::STATE_NORMAL ? | |
226 border_color : BorderColor(view, right_button_->state()); | |
227 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); | |
228 break; | |
229 } | |
230 | |
231 case RIGHT_BUTTON: | |
232 DrawBackground(canvas, view, gfx::Rect(0, 1, w - 1, h - 2), state); | |
233 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border_color); | |
234 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); | |
235 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); | |
236 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); | |
237 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border_color); | |
238 break; | |
239 | |
240 case SINGLE_BUTTON: | |
241 DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); | |
242 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border_color); | |
243 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); | |
244 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); | |
245 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); | |
246 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border_color); | |
247 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); | |
248 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); | |
249 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); | |
250 break; | |
251 | |
252 default: | |
253 NOTREACHED(); | |
254 break; | |
255 } | |
256 } | 169 } |
257 | 170 |
258 private: | 171 private: |
259 static SkColor BorderColor(View* view, views::Button::ButtonState state) { | 172 static SkColor BorderColor(View* view, views::Button::ButtonState state) { |
260 ui::NativeTheme* theme = view->GetNativeTheme(); | 173 ui::NativeTheme* theme = view->GetNativeTheme(); |
261 switch (state) { | 174 switch (state) { |
262 case views::Button::STATE_HOVERED: | 175 case views::Button::STATE_HOVERED: |
263 return theme->GetSystemColor( | 176 return theme->GetSystemColor( |
264 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); | 177 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); |
265 case views::Button::STATE_PRESSED: | 178 case views::Button::STATE_PRESSED: |
(...skipping 27 matching lines...) Expand all Loading... |
293 const views::View* view, | 206 const views::View* view, |
294 const gfx::Rect& bounds, | 207 const gfx::Rect& bounds, |
295 views::Button::ButtonState state) const { | 208 views::Button::ButtonState state) const { |
296 if (state == views::Button::STATE_HOVERED || | 209 if (state == views::Button::STATE_HOVERED || |
297 state == views::Button::STATE_PRESSED) { | 210 state == views::Button::STATE_PRESSED) { |
298 view->GetNativeTheme()->Paint(canvas->sk_canvas(), | 211 view->GetNativeTheme()->Paint(canvas->sk_canvas(), |
299 ui::NativeTheme::kMenuItemBackground, | 212 ui::NativeTheme::kMenuItemBackground, |
300 ui::NativeTheme::kHovered, | 213 ui::NativeTheme::kHovered, |
301 bounds, | 214 bounds, |
302 ui::NativeTheme::ExtraParams()); | 215 ui::NativeTheme::ExtraParams()); |
303 return; | |
304 } | 216 } |
305 if (use_new_menu_) | |
306 return; | |
307 canvas->FillRect(bounds, BackgroundColor(view, state)); | |
308 } | 217 } |
309 | 218 |
310 ButtonType TypeAdjustedForRTL() const { | 219 ButtonType TypeAdjustedForRTL() const { |
311 if (!base::i18n::IsRTL()) | 220 if (!base::i18n::IsRTL()) |
312 return type_; | 221 return type_; |
313 | 222 |
314 switch (type_) { | 223 switch (type_) { |
315 case LEFT_BUTTON: return RIGHT_BUTTON; | 224 case LEFT_BUTTON: return RIGHT_BUTTON; |
316 case RIGHT_BUTTON: return LEFT_BUTTON; | 225 case RIGHT_BUTTON: return LEFT_BUTTON; |
317 default: break; | 226 default: break; |
318 } | 227 } |
319 return type_; | 228 return type_; |
320 } | 229 } |
321 | 230 |
322 const ButtonType type_; | 231 const ButtonType type_; |
323 const bool use_new_menu_; | |
324 | 232 |
325 // See description above setter for details. | 233 // See description above setter for details. |
326 const CustomButton* left_button_; | 234 const CustomButton* left_button_; |
327 const CustomButton* right_button_; | 235 const CustomButton* right_button_; |
328 | 236 |
329 DISALLOW_COPY_AND_ASSIGN(InMenuButtonBackground); | 237 DISALLOW_COPY_AND_ASSIGN(InMenuButtonBackground); |
330 }; | 238 }; |
331 | 239 |
332 base::string16 GetAccessibleNameForWrenchMenuItem( | 240 base::string16 GetAccessibleNameForWrenchMenuItem( |
333 MenuModel* model, int item_index, int accessible_string_id) { | 241 MenuModel* model, int item_index, int accessible_string_id) { |
334 base::string16 accessible_name = | 242 base::string16 accessible_name = |
335 l10n_util::GetStringUTF16(accessible_string_id); | 243 l10n_util::GetStringUTF16(accessible_string_id); |
336 base::string16 accelerator_text; | 244 base::string16 accelerator_text; |
337 | 245 |
338 ui::Accelerator menu_accelerator; | 246 ui::Accelerator menu_accelerator; |
339 if (model->GetAcceleratorAt(item_index, &menu_accelerator)) { | 247 if (model->GetAcceleratorAt(item_index, &menu_accelerator)) { |
340 accelerator_text = | 248 accelerator_text = |
341 ui::Accelerator(menu_accelerator.key_code(), | 249 ui::Accelerator(menu_accelerator.key_code(), |
342 menu_accelerator.modifiers()).GetShortcutText(); | 250 menu_accelerator.modifiers()).GetShortcutText(); |
343 } | 251 } |
344 | 252 |
345 return MenuItemView::GetAccessibleNameForMenuItem( | 253 return MenuItemView::GetAccessibleNameForMenuItem( |
346 accessible_name, accelerator_text); | 254 accessible_name, accelerator_text); |
347 } | 255 } |
348 | 256 |
349 // A button that lives inside a menu item. | 257 // A button that lives inside a menu item. |
350 class InMenuButton : public LabelButton { | 258 class InMenuButton : public LabelButton { |
351 public: | 259 public: |
352 InMenuButton(views::ButtonListener* listener, | 260 InMenuButton(views::ButtonListener* listener, const base::string16& text) |
353 const base::string16& text, | 261 : LabelButton(listener, text), in_menu_background_(NULL) {} |
354 bool use_new_menu) | |
355 : LabelButton(listener, text), | |
356 use_new_menu_(use_new_menu), | |
357 in_menu_background_(NULL) {} | |
358 virtual ~InMenuButton() {} | 262 virtual ~InMenuButton() {} |
359 | 263 |
360 void Init(InMenuButtonBackground::ButtonType type) { | 264 void Init(InMenuButtonBackground::ButtonType type) { |
361 SetFocusable(true); | 265 SetFocusable(true); |
362 set_request_focus_on_press(false); | 266 set_request_focus_on_press(false); |
363 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 267 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
364 | 268 |
365 in_menu_background_ = new InMenuButtonBackground(type, use_new_menu_); | 269 in_menu_background_ = new InMenuButtonBackground(type); |
366 set_background(in_menu_background_); | 270 set_background(in_menu_background_); |
367 | 271 |
368 OnNativeThemeChanged(NULL); | 272 OnNativeThemeChanged(NULL); |
369 } | 273 } |
370 | 274 |
371 void SetOtherButtons(const InMenuButton* left, const InMenuButton* right) { | 275 void SetOtherButtons(const InMenuButton* left, const InMenuButton* right) { |
372 in_menu_background_->SetOtherButtons(left, right); | 276 in_menu_background_->SetOtherButtons(left, right); |
373 } | 277 } |
374 | 278 |
375 // views::LabelButton | 279 // views::LabelButton |
376 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { | 280 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { |
377 const MenuConfig& menu_config = MenuConfig::instance(theme); | 281 const MenuConfig& menu_config = MenuConfig::instance(theme); |
378 SetBorder(scoped_ptr<views::Border>( | 282 SetBorder(views::Border::CreateEmptyBorder( |
379 new MenuButtonBorder(menu_config, use_new_menu_))); | 283 0, kHorizontalPadding, 0, kHorizontalPadding)); |
380 SetFontList(menu_config.font_list); | 284 SetFontList(menu_config.font_list); |
381 | 285 |
382 if (theme) { | 286 if (theme) { |
383 SetTextColor( | 287 SetTextColor( |
384 views::Button::STATE_DISABLED, | 288 views::Button::STATE_DISABLED, |
385 theme->GetSystemColor( | 289 theme->GetSystemColor( |
386 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); | 290 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); |
387 SetTextColor( | 291 SetTextColor( |
388 views::Button::STATE_HOVERED, | 292 views::Button::STATE_HOVERED, |
389 theme->GetSystemColor( | 293 theme->GetSystemColor( |
390 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | 294 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
391 SetTextColor( | 295 SetTextColor( |
392 views::Button::STATE_PRESSED, | 296 views::Button::STATE_PRESSED, |
393 theme->GetSystemColor( | 297 theme->GetSystemColor( |
394 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | 298 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
395 SetTextColor( | 299 SetTextColor( |
396 views::Button::STATE_NORMAL, | 300 views::Button::STATE_NORMAL, |
397 theme->GetSystemColor( | 301 theme->GetSystemColor( |
398 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); | 302 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
399 } | 303 } |
400 } | 304 } |
401 | 305 |
402 private: | 306 private: |
403 bool use_new_menu_; | |
404 | |
405 InMenuButtonBackground* in_menu_background_; | 307 InMenuButtonBackground* in_menu_background_; |
406 | 308 |
407 DISALLOW_COPY_AND_ASSIGN(InMenuButton); | 309 DISALLOW_COPY_AND_ASSIGN(InMenuButton); |
408 }; | 310 }; |
409 | 311 |
410 // WrenchMenuView is a view that can contain label buttons. | 312 // WrenchMenuView is a view that can contain label buttons. |
411 class WrenchMenuView : public views::View, | 313 class WrenchMenuView : public views::View, |
412 public views::ButtonListener, | 314 public views::ButtonListener, |
413 public WrenchMenuObserver { | 315 public WrenchMenuObserver { |
414 public: | 316 public: |
(...skipping 25 matching lines...) Expand all Loading... |
440 } | 342 } |
441 | 343 |
442 InMenuButton* CreateButtonWithAccName(int string_id, | 344 InMenuButton* CreateButtonWithAccName(int string_id, |
443 InMenuButtonBackground::ButtonType type, | 345 InMenuButtonBackground::ButtonType type, |
444 int index, | 346 int index, |
445 int acc_string_id) { | 347 int acc_string_id) { |
446 // Should only be invoked during construction when |menu_| is valid. | 348 // Should only be invoked during construction when |menu_| is valid. |
447 DCHECK(menu_); | 349 DCHECK(menu_); |
448 InMenuButton* button = new InMenuButton( | 350 InMenuButton* button = new InMenuButton( |
449 this, | 351 this, |
450 gfx::RemoveAcceleratorChar(l10n_util::GetStringUTF16(string_id), | 352 gfx::RemoveAcceleratorChar( |
451 '&', | 353 l10n_util::GetStringUTF16(string_id), '&', NULL, NULL)); |
452 NULL, | |
453 NULL), | |
454 use_new_menu()); | |
455 button->Init(type); | 354 button->Init(type); |
456 button->SetAccessibleName( | 355 button->SetAccessibleName( |
457 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); | 356 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); |
458 button->set_tag(index); | 357 button->set_tag(index); |
459 button->SetEnabled(menu_model_->IsEnabledAt(index)); | 358 button->SetEnabled(menu_model_->IsEnabledAt(index)); |
460 | 359 |
461 AddChildView(button); | 360 AddChildView(button); |
462 // all buttons on menu should must be a custom button in order for | 361 // all buttons on menu should must be a custom button in order for |
463 // the keyboard nativigation work. | 362 // the keyboard nativigation work. |
464 DCHECK(CustomButton::AsCustomButton(button)); | 363 DCHECK(CustomButton::AsCustomButton(button)); |
465 return button; | 364 return button; |
466 } | 365 } |
467 | 366 |
468 // Overridden from WrenchMenuObserver: | 367 // Overridden from WrenchMenuObserver: |
469 virtual void WrenchMenuDestroyed() OVERRIDE { | 368 virtual void WrenchMenuDestroyed() OVERRIDE { |
470 menu_->RemoveObserver(this); | 369 menu_->RemoveObserver(this); |
471 menu_ = NULL; | 370 menu_ = NULL; |
472 menu_model_ = NULL; | 371 menu_model_ = NULL; |
473 } | 372 } |
474 | 373 |
475 protected: | 374 protected: |
476 WrenchMenu* menu() { return menu_; } | 375 WrenchMenu* menu() { return menu_; } |
477 MenuModel* menu_model() { return menu_model_; } | 376 MenuModel* menu_model() { return menu_model_; } |
478 | 377 |
479 bool use_new_menu() const { return menu_->use_new_menu(); } | |
480 | |
481 private: | 378 private: |
482 // Hosting WrenchMenu. | 379 // Hosting WrenchMenu. |
483 // WARNING: this may be NULL during shutdown. | 380 // WARNING: this may be NULL during shutdown. |
484 WrenchMenu* menu_; | 381 WrenchMenu* menu_; |
485 | 382 |
486 // The menu model containing the increment/decrement/reset items. | 383 // The menu model containing the increment/decrement/reset items. |
487 // WARNING: this may be NULL during shutdown. | 384 // WARNING: this may be NULL during shutdown. |
488 MenuModel* menu_model_; | 385 MenuModel* menu_model_; |
489 | 386 |
490 DISALLOW_COPY_AND_ASSIGN(WrenchMenuView); | 387 DISALLOW_COPY_AND_ASSIGN(WrenchMenuView); |
491 }; | 388 }; |
492 | 389 |
493 class ButtonContainerMenuItemView : public MenuItemView { | |
494 public: | |
495 // Constructor for use with button containing menu items which have a | |
496 // different height then normal items. | |
497 ButtonContainerMenuItemView(MenuItemView* parent, int command_id, int height) | |
498 : MenuItemView(parent, command_id, MenuItemView::NORMAL), | |
499 height_(height) {} | |
500 | |
501 // Overridden from MenuItemView. | |
502 virtual gfx::Size GetChildPreferredSize() const OVERRIDE { | |
503 gfx::Size size = MenuItemView::GetChildPreferredSize(); | |
504 // When there is a height override given, we need to deduct our spacing | |
505 // above and below to get to the correct height to return here for the | |
506 // child item. | |
507 int height = height_ - GetTopMargin() - GetBottomMargin(); | |
508 if (height > size.height()) | |
509 size.set_height(height); | |
510 return size; | |
511 } | |
512 | |
513 private: | |
514 int height_; | |
515 | |
516 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); | |
517 }; | |
518 | |
519 // Generate the button image for hover state. | 390 // Generate the button image for hover state. |
520 class HoveredImageSource : public gfx::ImageSkiaSource { | 391 class HoveredImageSource : public gfx::ImageSkiaSource { |
521 public: | 392 public: |
522 HoveredImageSource(const gfx::ImageSkia& image, SkColor color) | 393 HoveredImageSource(const gfx::ImageSkia& image, SkColor color) |
523 : image_(image), | 394 : image_(image), |
524 color_(color) { | 395 color_(color) { |
525 } | 396 } |
526 virtual ~HoveredImageSource() {} | 397 virtual ~HoveredImageSource() {} |
527 | 398 |
528 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 399 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
(...skipping 29 matching lines...) Expand all Loading... |
558 // CutCopyPasteView is the view containing the cut/copy/paste buttons. | 429 // CutCopyPasteView is the view containing the cut/copy/paste buttons. |
559 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { | 430 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
560 public: | 431 public: |
561 CutCopyPasteView(WrenchMenu* menu, | 432 CutCopyPasteView(WrenchMenu* menu, |
562 MenuModel* menu_model, | 433 MenuModel* menu_model, |
563 int cut_index, | 434 int cut_index, |
564 int copy_index, | 435 int copy_index, |
565 int paste_index) | 436 int paste_index) |
566 : WrenchMenuView(menu, menu_model) { | 437 : WrenchMenuView(menu, menu_model) { |
567 InMenuButton* cut = CreateAndConfigureButton( | 438 InMenuButton* cut = CreateAndConfigureButton( |
568 IDS_CUT, InMenuButtonBackground::LEFT_BUTTON, | 439 IDS_CUT, InMenuButtonBackground::LEFT_BUTTON, cut_index); |
569 cut_index); | |
570 InMenuButton* copy = CreateAndConfigureButton( | 440 InMenuButton* copy = CreateAndConfigureButton( |
571 IDS_COPY, InMenuButtonBackground::CENTER_BUTTON, | 441 IDS_COPY, InMenuButtonBackground::CENTER_BUTTON, copy_index); |
572 copy_index); | |
573 InMenuButton* paste = CreateAndConfigureButton( | 442 InMenuButton* paste = CreateAndConfigureButton( |
574 IDS_PASTE, | 443 IDS_PASTE, InMenuButtonBackground::CENTER_BUTTON, paste_index); |
575 menu->use_new_menu() && menu->supports_new_separators() ? | |
576 InMenuButtonBackground::CENTER_BUTTON : | |
577 InMenuButtonBackground::RIGHT_BUTTON, | |
578 paste_index); | |
579 copy->SetOtherButtons(cut, paste); | 444 copy->SetOtherButtons(cut, paste); |
580 } | 445 } |
581 | 446 |
582 // Overridden from View. | 447 // Overridden from View. |
583 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 448 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
584 // Returned height doesn't matter as MenuItemView forces everything to the | 449 // Returned height doesn't matter as MenuItemView forces everything to the |
585 // height of the menuitemview. | 450 // height of the menuitemview. |
586 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); | 451 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); |
587 } | 452 } |
588 | 453 |
(...skipping 17 matching lines...) Expand all Loading... |
606 for (int i = 0; i < child_count(); ++i) | 471 for (int i = 0; i < child_count(); ++i) |
607 width = std::max(width, child_at(i)->GetPreferredSize().width()); | 472 width = std::max(width, child_at(i)->GetPreferredSize().width()); |
608 return width; | 473 return width; |
609 } | 474 } |
610 | 475 |
611 DISALLOW_COPY_AND_ASSIGN(CutCopyPasteView); | 476 DISALLOW_COPY_AND_ASSIGN(CutCopyPasteView); |
612 }; | 477 }; |
613 | 478 |
614 // ZoomView -------------------------------------------------------------------- | 479 // ZoomView -------------------------------------------------------------------- |
615 | 480 |
616 // Padding between the increment buttons and the reset button. | |
617 static const int kZoomPadding = 6; | |
618 static const int kTouchZoomPadding = 14; | |
619 | 481 |
620 // ZoomView contains the various zoom controls: two buttons to increase/decrease | 482 // ZoomView contains the various zoom controls: two buttons to increase/decrease |
621 // the zoom, a label showing the current zoom percent, and a button to go | 483 // the zoom, a label showing the current zoom percent, and a button to go |
622 // full-screen. | 484 // full-screen. |
623 class WrenchMenu::ZoomView : public WrenchMenuView { | 485 class WrenchMenu::ZoomView : public WrenchMenuView { |
624 public: | 486 public: |
625 ZoomView(WrenchMenu* menu, | 487 ZoomView(WrenchMenu* menu, |
626 MenuModel* menu_model, | 488 MenuModel* menu_model, |
627 int decrement_index, | 489 int decrement_index, |
628 int increment_index, | 490 int increment_index, |
(...skipping 17 matching lines...) Expand all Loading... |
646 | 508 |
647 decrement_button_ = CreateButtonWithAccName( | 509 decrement_button_ = CreateButtonWithAccName( |
648 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, | 510 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, |
649 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); | 511 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); |
650 | 512 |
651 zoom_label_ = new Label( | 513 zoom_label_ = new Label( |
652 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); | 514 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); |
653 zoom_label_->SetAutoColorReadabilityEnabled(false); | 515 zoom_label_->SetAutoColorReadabilityEnabled(false); |
654 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 516 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
655 | 517 |
656 InMenuButtonBackground* center_bg = new InMenuButtonBackground( | 518 InMenuButtonBackground* center_bg = |
657 menu->use_new_menu() && menu->supports_new_separators() ? | 519 new InMenuButtonBackground(InMenuButtonBackground::RIGHT_BUTTON); |
658 InMenuButtonBackground::RIGHT_BUTTON : | |
659 InMenuButtonBackground::CENTER_BUTTON, | |
660 menu->use_new_menu()); | |
661 zoom_label_->set_background(center_bg); | 520 zoom_label_->set_background(center_bg); |
662 | 521 |
663 AddChildView(zoom_label_); | 522 AddChildView(zoom_label_); |
664 zoom_label_width_ = MaxWidthForZoomLabel(); | 523 zoom_label_width_ = MaxWidthForZoomLabel(); |
665 | 524 |
666 increment_button_ = CreateButtonWithAccName( | 525 increment_button_ = CreateButtonWithAccName( |
667 IDS_ZOOM_PLUS2, InMenuButtonBackground::RIGHT_BUTTON, | 526 IDS_ZOOM_PLUS2, InMenuButtonBackground::RIGHT_BUTTON, |
668 increment_index, IDS_ACCNAME_ZOOM_PLUS2); | 527 increment_index, IDS_ACCNAME_ZOOM_PLUS2); |
669 | 528 |
670 center_bg->SetOtherButtons(decrement_button_, increment_button_); | 529 center_bg->SetOtherButtons(decrement_button_, increment_button_); |
671 | 530 |
672 fullscreen_button_ = new FullscreenButton(this); | 531 fullscreen_button_ = new FullscreenButton(this); |
673 // all buttons on menu should must be a custom button in order for | 532 // all buttons on menu should must be a custom button in order for |
674 // the keyboard nativigation work. | 533 // the keyboard nativigation work. |
675 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); | 534 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); |
676 gfx::ImageSkia* full_screen_image = | 535 gfx::ImageSkia* full_screen_image = |
677 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 536 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
678 IDR_FULLSCREEN_MENU_BUTTON); | 537 IDR_FULLSCREEN_MENU_BUTTON); |
679 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); | 538 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
680 | 539 |
681 fullscreen_button_->SetFocusable(true); | 540 fullscreen_button_->SetFocusable(true); |
682 fullscreen_button_->set_request_focus_on_press(false); | 541 fullscreen_button_->set_request_focus_on_press(false); |
683 fullscreen_button_->set_tag(fullscreen_index); | 542 fullscreen_button_->set_tag(fullscreen_index); |
684 fullscreen_button_->SetImageAlignment( | 543 fullscreen_button_->SetImageAlignment( |
685 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 544 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
686 int horizontal_padding = | 545 fullscreen_button_->set_background( |
687 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; | 546 new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON)); |
688 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( | |
689 0, horizontal_padding, 0, horizontal_padding)); | |
690 fullscreen_button_->set_background(new InMenuButtonBackground( | |
691 InMenuButtonBackground::SINGLE_BUTTON, menu->use_new_menu())); | |
692 fullscreen_button_->SetAccessibleName( | 547 fullscreen_button_->SetAccessibleName( |
693 GetAccessibleNameForWrenchMenuItem( | 548 GetAccessibleNameForWrenchMenuItem( |
694 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); | 549 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
695 AddChildView(fullscreen_button_); | 550 AddChildView(fullscreen_button_); |
696 | 551 |
697 // Need to set a font list for the zoom label width calculations. | 552 // Need to set a font list for the zoom label width calculations. |
698 OnNativeThemeChanged(NULL); | 553 OnNativeThemeChanged(NULL); |
699 UpdateZoomControls(); | 554 UpdateZoomControls(); |
700 } | 555 } |
701 | 556 |
702 virtual ~ZoomView() {} | 557 virtual ~ZoomView() {} |
703 | 558 |
704 // Overridden from View. | 559 // Overridden from View. |
705 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 560 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
706 // The increment/decrement button are forced to the same width. | 561 // The increment/decrement button are forced to the same width. |
707 int button_width = std::max(increment_button_->GetPreferredSize().width(), | 562 int button_width = std::max(increment_button_->GetPreferredSize().width(), |
708 decrement_button_->GetPreferredSize().width()); | 563 decrement_button_->GetPreferredSize().width()); |
709 int zoom_padding = use_new_menu() ? | 564 int fullscreen_width = |
710 kTouchZoomPadding : kZoomPadding; | 565 fullscreen_button_->GetPreferredSize().width() + kFullscreenPadding; |
711 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + | |
712 zoom_padding; | |
713 // Returned height doesn't matter as MenuItemView forces everything to the | 566 // Returned height doesn't matter as MenuItemView forces everything to the |
714 // height of the menuitemview. Note that we have overridden the height when | 567 // height of the menuitemview. Note that we have overridden the height when |
715 // constructing the menu. | 568 // constructing the menu. |
716 return gfx::Size(button_width + zoom_label_width_ + button_width + | 569 return gfx::Size(button_width + zoom_label_width_ + button_width + |
717 fullscreen_width, 0); | 570 fullscreen_width, 0); |
718 } | 571 } |
719 | 572 |
720 virtual void Layout() OVERRIDE { | 573 virtual void Layout() OVERRIDE { |
721 int x = 0; | 574 int x = 0; |
722 int button_width = std::max(increment_button_->GetPreferredSize().width(), | 575 int button_width = std::max(increment_button_->GetPreferredSize().width(), |
723 decrement_button_->GetPreferredSize().width()); | 576 decrement_button_->GetPreferredSize().width()); |
724 gfx::Rect bounds(0, 0, button_width, height()); | 577 gfx::Rect bounds(0, 0, button_width, height()); |
725 | 578 |
726 decrement_button_->SetBoundsRect(bounds); | 579 decrement_button_->SetBoundsRect(bounds); |
727 | 580 |
728 x += bounds.width(); | 581 x += bounds.width(); |
729 bounds.set_x(x); | 582 bounds.set_x(x); |
730 bounds.set_width(zoom_label_width_); | 583 bounds.set_width(zoom_label_width_); |
731 zoom_label_->SetBoundsRect(bounds); | 584 zoom_label_->SetBoundsRect(bounds); |
732 | 585 |
733 x += bounds.width(); | 586 x += bounds.width(); |
734 bounds.set_x(x); | 587 bounds.set_x(x); |
735 bounds.set_width(button_width); | 588 bounds.set_width(button_width); |
736 increment_button_->SetBoundsRect(bounds); | 589 increment_button_->SetBoundsRect(bounds); |
737 | 590 |
738 x += bounds.width() + (use_new_menu() ? 0 : kZoomPadding); | 591 x += bounds.width(); |
739 bounds.set_x(x); | 592 bounds.set_x(x); |
740 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + | 593 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + |
741 (use_new_menu() ? kTouchZoomPadding : 0)); | 594 kFullscreenPadding); |
742 fullscreen_button_->SetBoundsRect(bounds); | 595 fullscreen_button_->SetBoundsRect(bounds); |
743 } | 596 } |
744 | 597 |
745 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { | 598 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { |
746 WrenchMenuView::OnNativeThemeChanged(theme); | 599 WrenchMenuView::OnNativeThemeChanged(theme); |
747 | 600 |
748 const MenuConfig& menu_config = MenuConfig::instance(theme); | 601 const MenuConfig& menu_config = MenuConfig::instance(theme); |
749 zoom_label_->SetBorder(scoped_ptr<views::Border>( | 602 zoom_label_->SetBorder(views::Border::CreateEmptyBorder( |
750 new MenuButtonBorder(menu_config, menu()->use_new_menu()))); | 603 0, kZoomLabelHorizontalPadding, 0, kZoomLabelHorizontalPadding)); |
751 zoom_label_->SetFontList(menu_config.font_list); | 604 zoom_label_->SetFontList(menu_config.font_list); |
752 zoom_label_width_ = MaxWidthForZoomLabel(); | 605 zoom_label_width_ = MaxWidthForZoomLabel(); |
753 | 606 |
754 if (theme) { | 607 if (theme) { |
755 zoom_label_->SetEnabledColor(theme->GetSystemColor( | 608 zoom_label_->SetEnabledColor(theme->GetSystemColor( |
756 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); | 609 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
757 gfx::ImageSkia* full_screen_image = | 610 gfx::ImageSkia* full_screen_image = |
758 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 611 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
759 IDR_FULLSCREEN_MENU_BUTTON); | 612 IDR_FULLSCREEN_MENU_BUTTON); |
760 SkColor fg_color = theme->GetSystemColor( | 613 SkColor fg_color = theme->GetSystemColor( |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 while (iter != wrench_menu_->command_id_to_entry_.end()) { | 773 while (iter != wrench_menu_->command_id_to_entry_.end()) { |
921 if (iter->second.first == model_) | 774 if (iter->second.first == model_) |
922 wrench_menu_->command_id_to_entry_.erase(iter++); | 775 wrench_menu_->command_id_to_entry_.erase(iter++); |
923 else | 776 else |
924 ++iter; | 777 ++iter; |
925 } | 778 } |
926 } | 779 } |
927 | 780 |
928 // Add all menu items from |model| to submenu. | 781 // Add all menu items from |model| to submenu. |
929 for (int i = 0; i < model_->GetItemCount(); ++i) { | 782 for (int i = 0; i < model_->GetItemCount(); ++i) { |
930 wrench_menu_->AddMenuItem(menu_item_, i, model_, i, model_->GetTypeAt(i), | 783 wrench_menu_->AddMenuItem(menu_item_, i, model_, i, model_->GetTypeAt(i)); |
931 0); | |
932 } | 784 } |
933 | 785 |
934 // In case recent tabs submenu was open when items were changing, force a | 786 // In case recent tabs submenu was open when items were changing, force a |
935 // ChildrenChanged(). | 787 // ChildrenChanged(). |
936 menu_item_->ChildrenChanged(); | 788 menu_item_->ChildrenChanged(); |
937 } | 789 } |
938 | 790 |
939 private: | 791 private: |
940 WrenchMenu* wrench_menu_; | 792 WrenchMenu* wrench_menu_; |
941 ui::MenuModel* model_; | 793 ui::MenuModel* model_; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 root_->Cancel(); | 1102 root_->Cancel(); |
1251 break; | 1103 break; |
1252 default: | 1104 default: |
1253 NOTREACHED(); | 1105 NOTREACHED(); |
1254 } | 1106 } |
1255 } | 1107 } |
1256 | 1108 |
1257 void WrenchMenu::PopulateMenu(MenuItemView* parent, | 1109 void WrenchMenu::PopulateMenu(MenuItemView* parent, |
1258 MenuModel* model) { | 1110 MenuModel* model) { |
1259 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { | 1111 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { |
1260 // The button container menu items have a special height which we have to | |
1261 // use instead of the normal height. | |
1262 int height = 0; | |
1263 if (use_new_menu() && | |
1264 (model->GetCommandIdAt(i) == IDC_CUT || | |
1265 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) | |
1266 height = kMenuItemContainingButtonsHeight; | |
1267 | |
1268 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar_menu_view; | |
1269 if (model->GetCommandIdAt(i) == IDC_EXTENSIONS_OVERFLOW_MENU) { | |
1270 extension_toolbar_menu_view.reset( | |
1271 new ExtensionToolbarMenuView(browser_, this)); | |
1272 height = extension_toolbar_menu_view->GetPreferredSize().height(); | |
1273 } | |
1274 | |
1275 // Add the menu item at the end. | 1112 // Add the menu item at the end. |
1276 int menu_index = parent->HasSubmenu() ? | 1113 int menu_index = parent->HasSubmenu() ? |
1277 parent->GetSubmenu()->child_count() : 0; | 1114 parent->GetSubmenu()->child_count() : 0; |
1278 MenuItemView* item = AddMenuItem( | 1115 MenuItemView* item = |
1279 parent, menu_index, model, i, model->GetTypeAt(i), height); | 1116 AddMenuItem(parent, menu_index, model, i, model->GetTypeAt(i)); |
| 1117 |
| 1118 if (model->GetCommandIdAt(i) == IDC_CUT || |
| 1119 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS) { |
| 1120 const MenuConfig& config = item->GetMenuConfig(); |
| 1121 int top_margin = config.item_top_margin + config.separator_height / 2; |
| 1122 int bottom_margin = |
| 1123 config.item_bottom_margin + config.separator_height / 2; |
| 1124 |
| 1125 // Chromeos adds extra vertical space for the menu buttons. |
| 1126 #if defined(OS_CHROMEOS) |
| 1127 top_margin += 4; |
| 1128 bottom_margin += 5; |
| 1129 #endif |
| 1130 |
| 1131 item->SetMargins(top_margin, bottom_margin); |
| 1132 } |
1280 | 1133 |
1281 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) | 1134 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) |
1282 PopulateMenu(item, model->GetSubmenuModelAt(i)); | 1135 PopulateMenu(item, model->GetSubmenuModelAt(i)); |
1283 | 1136 |
1284 switch (model->GetCommandIdAt(i)) { | 1137 switch (model->GetCommandIdAt(i)) { |
1285 case IDC_EXTENSIONS_OVERFLOW_MENU: | 1138 case IDC_EXTENSIONS_OVERFLOW_MENU: { |
1286 if (height > 0) | 1139 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar( |
1287 item->AddChildView(extension_toolbar_menu_view.release()); | 1140 new ExtensionToolbarMenuView(browser_, this)); |
| 1141 if (extension_toolbar->GetPreferredSize().height() > 0) |
| 1142 item->AddChildView(extension_toolbar.release()); |
1288 else | 1143 else |
1289 item->SetVisible(false); | 1144 item->SetVisible(false); |
1290 break; | 1145 break; |
| 1146 } |
| 1147 |
1291 case IDC_CUT: | 1148 case IDC_CUT: |
1292 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1149 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
1293 DCHECK_LT(i + 2, max); | 1150 DCHECK_LT(i + 2, max); |
1294 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); | 1151 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); |
1295 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); | 1152 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); |
1296 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); | 1153 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); |
1297 item->AddChildView(new CutCopyPasteView(this, model, | 1154 item->AddChildView(new CutCopyPasteView(this, model, |
1298 i, i + 1, i + 2)); | 1155 i, i + 1, i + 2)); |
1299 i += 2; | 1156 i += 2; |
1300 break; | 1157 break; |
(...skipping 29 matching lines...) Expand all Loading... |
1330 default: | 1187 default: |
1331 break; | 1188 break; |
1332 } | 1189 } |
1333 } | 1190 } |
1334 } | 1191 } |
1335 | 1192 |
1336 MenuItemView* WrenchMenu::AddMenuItem(MenuItemView* parent, | 1193 MenuItemView* WrenchMenu::AddMenuItem(MenuItemView* parent, |
1337 int menu_index, | 1194 int menu_index, |
1338 MenuModel* model, | 1195 MenuModel* model, |
1339 int model_index, | 1196 int model_index, |
1340 MenuModel::ItemType menu_type, | 1197 MenuModel::ItemType menu_type) { |
1341 int height) { | |
1342 int command_id = model->GetCommandIdAt(model_index); | 1198 int command_id = model->GetCommandIdAt(model_index); |
1343 DCHECK(command_id > -1 || | 1199 DCHECK(command_id > -1 || |
1344 (command_id == -1 && | 1200 (command_id == -1 && |
1345 model->GetTypeAt(model_index) == MenuModel::TYPE_SEPARATOR)); | 1201 model->GetTypeAt(model_index) == MenuModel::TYPE_SEPARATOR)); |
1346 | 1202 |
1347 if (command_id > -1) { // Don't add separators to |command_id_to_entry_|. | 1203 if (command_id > -1) { // Don't add separators to |command_id_to_entry_|. |
1348 // All command ID's should be unique except for IDC_SHOW_HISTORY which is | 1204 // All command ID's should be unique except for IDC_SHOW_HISTORY which is |
1349 // in both wrench menu and RecentTabs submenu, | 1205 // in both wrench menu and RecentTabs submenu, |
1350 if (command_id != IDC_SHOW_HISTORY) { | 1206 if (command_id != IDC_SHOW_HISTORY) { |
1351 DCHECK(command_id_to_entry_.find(command_id) == | 1207 DCHECK(command_id_to_entry_.find(command_id) == |
1352 command_id_to_entry_.end()) | 1208 command_id_to_entry_.end()) |
1353 << "command ID " << command_id << " already exists!"; | 1209 << "command ID " << command_id << " already exists!"; |
1354 } | 1210 } |
1355 command_id_to_entry_[command_id].first = model; | 1211 command_id_to_entry_[command_id].first = model; |
1356 command_id_to_entry_[command_id].second = model_index; | 1212 command_id_to_entry_[command_id].second = model_index; |
1357 } | 1213 } |
1358 | 1214 |
1359 MenuItemView* menu_item = NULL; | 1215 MenuItemView* menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt( |
1360 if (height > 0) { | 1216 model, model_index, parent, menu_index, command_id); |
1361 // For menu items with a special menu height we use our special class to be | |
1362 // able to modify the item height. | |
1363 menu_item = new ButtonContainerMenuItemView(parent, command_id, height); | |
1364 if (!parent->GetSubmenu()) | |
1365 parent->CreateSubmenu(); | |
1366 parent->GetSubmenu()->AddChildViewAt(menu_item, menu_index); | |
1367 } else { | |
1368 // For all other cases we use the more generic way to add menu items. | |
1369 menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt( | |
1370 model, model_index, parent, menu_index, command_id); | |
1371 } | |
1372 | 1217 |
1373 if (menu_item) { | 1218 if (menu_item) { |
1374 // Flush all buttons to the right side of the menu for the new menu type. | 1219 // Flush all buttons to the right side of the menu for the new menu type. |
1375 menu_item->set_use_right_margin(!use_new_menu()); | 1220 menu_item->set_use_right_margin(false); |
1376 menu_item->SetVisible(model->IsVisibleAt(model_index)); | 1221 menu_item->SetVisible(model->IsVisibleAt(model_index)); |
1377 | 1222 |
1378 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) { | 1223 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) { |
1379 gfx::Image icon; | 1224 gfx::Image icon; |
1380 if (model->GetIconAt(model_index, &icon)) | 1225 if (model->GetIconAt(model_index, &icon)) |
1381 menu_item->SetIcon(*icon.ToImageSkia()); | 1226 menu_item->SetIcon(*icon.ToImageSkia()); |
1382 } | 1227 } |
1383 } | 1228 } |
1384 | 1229 |
1385 return menu_item; | 1230 return menu_item; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 0, | 1262 0, |
1418 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1263 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1419 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1264 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
1420 } | 1265 } |
1421 | 1266 |
1422 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1267 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
1423 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1268 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1424 DCHECK(ix != command_id_to_entry_.end()); | 1269 DCHECK(ix != command_id_to_entry_.end()); |
1425 return ix->second.second; | 1270 return ix->second.second; |
1426 } | 1271 } |
OLD | NEW |