Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 using views::ImageButton; | 64 using views::ImageButton; |
| 65 using views::Label; | 65 using views::Label; |
| 66 using views::LabelButton; | 66 using views::LabelButton; |
| 67 using views::MenuConfig; | 67 using views::MenuConfig; |
| 68 using views::MenuItemView; | 68 using views::MenuItemView; |
| 69 using views::View; | 69 using views::View; |
| 70 | 70 |
| 71 namespace { | 71 namespace { |
| 72 | 72 |
| 73 // Colors used for buttons. | 73 // Colors used for buttons. |
| 74 const SkColor kHotBorderColor = SkColorSetARGB(72, 0, 0, 0); | 74 const SkColor kEnabledTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); |
| 75 const SkColor kBorderColor = SkColorSetARGB(36, 0, 0, 0); | 75 const SkColor kHoverTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); |
| 76 const SkColor kPushedBorderColor = SkColorSetARGB(72, 0, 0, 0); | 76 const SkColor kFocusedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); |
| 77 const SkColor kHotBackgroundColor = SkColorSetARGB(204, 255, 255, 255); | |
| 78 const SkColor kBackgroundColor = SkColorSetARGB(102, 255, 255, 255); | |
| 79 const SkColor kPushedBackgroundColor = SkColorSetARGB(13, 0, 0, 0); | |
| 80 const SkColor kTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); | |
| 81 const SkColor kHotTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); | |
| 82 const SkColor kPushedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); | |
| 83 | 77 |
| 84 const SkColor kTouchButtonText = 0xff5a5a5a; | 78 const SkColor kTouchButtonText = 0xff5a5a5a; |
| 85 | 79 |
| 86 // Horizontal padding on the edges of the buttons. | 80 // Horizontal padding on the edges of the buttons. |
| 87 const int kHorizontalPadding = 6; | 81 const int kHorizontalPadding = 6; |
| 88 // Horizontal padding for a touch enabled menu. | 82 // Horizontal padding for a touch enabled menu. |
| 89 const int kHorizontalTouchPadding = 15; | 83 const int kHorizontalTouchPadding = 15; |
| 90 | 84 |
| 91 // Menu items which have embedded buttons should have this height in pixel. | 85 // Menu items which have embedded buttons should have this height in pixel. |
| 92 const int kMenuItemContainingButtonsHeight = 43; | 86 const int kMenuItemContainingButtonsHeight = 43; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 #if defined(USE_AURA) | 174 #if defined(USE_AURA) |
| 181 if (use_new_menu_ && | 175 if (use_new_menu_ && |
| 182 view->GetNativeTheme() == ui::NativeThemeAura::instance()) { | 176 view->GetNativeTheme() == ui::NativeThemeAura::instance()) { |
| 183 // Normal buttons get a border drawn on the right side and the rest gets | 177 // Normal buttons get a border drawn on the right side and the rest gets |
| 184 // filled in. The left button however does not get a line to combine | 178 // filled in. The left button however does not get a line to combine |
| 185 // buttons. | 179 // buttons. |
| 186 int border = 0; | 180 int border = 0; |
| 187 if (type_ != RIGHT_BUTTON) { | 181 if (type_ != RIGHT_BUTTON) { |
| 188 border = 1; | 182 border = 1; |
| 189 canvas->FillRect(gfx::Rect(0, 0, border, h), | 183 canvas->FillRect(gfx::Rect(0, 0, border, h), |
| 190 border_color(CustomButton::STATE_NORMAL)); | 184 border_color(view, CustomButton::STATE_NORMAL)); |
| 191 } | 185 } |
| 192 canvas->FillRect(gfx::Rect(border, 0, w - border, h), | 186 canvas->FillRect(gfx::Rect(border, 0, w - border, h), |
| 193 touch_background_color(state)); | 187 touch_background_color(state)); |
| 194 return; | 188 return; |
| 195 } | 189 } |
| 196 #endif | 190 #endif |
| 191 const SkColor background = background_color(view, state); | |
| 192 const SkColor border = border_color(view, state); | |
| 197 switch (TypeAdjustedForRTL()) { | 193 switch (TypeAdjustedForRTL()) { |
| 198 case LEFT_BUTTON: | 194 case LEFT_BUTTON: |
| 199 canvas->FillRect(gfx::Rect(1, 1, w, h - 2), background_color(state)); | 195 canvas->FillRect(gfx::Rect(1, 1, w, h - 2), background); |
| 200 canvas->FillRect(gfx::Rect(2, 0, w, 1), border_color(state)); | 196 canvas->FillRect(gfx::Rect(2, 0, w, 1), border); |
| 201 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color(state)); | 197 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); |
| 202 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color(state)); | 198 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); |
| 203 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color(state)); | 199 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); |
| 204 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border_color(state)); | 200 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border); |
| 205 break; | 201 break; |
| 206 | 202 |
| 207 case CENTER_BUTTON: { | 203 case CENTER_BUTTON: { |
| 208 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), | 204 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); |
| 209 background_color(state)); | |
| 210 SkColor left_color = state != CustomButton::STATE_NORMAL ? | 205 SkColor left_color = state != CustomButton::STATE_NORMAL ? |
| 211 border_color(state) : border_color(left_button_->state()); | 206 border : border_color(view, left_button_->state()); |
| 212 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); | 207 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); |
| 213 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border_color(state)); | 208 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border); |
| 214 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), border_color(state)); | 209 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), |
| 210 border); | |
| 215 SkColor right_color = state != CustomButton::STATE_NORMAL ? | 211 SkColor right_color = state != CustomButton::STATE_NORMAL ? |
| 216 border_color(state) : border_color(right_button_->state()); | 212 border : border_color(view, right_button_->state()); |
| 217 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); | 213 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); |
| 218 break; | 214 break; |
| 219 } | 215 } |
| 220 | 216 |
| 221 case RIGHT_BUTTON: | 217 case RIGHT_BUTTON: |
| 222 canvas->FillRect(gfx::Rect(0, 1, w - 1, h - 2), | 218 canvas->FillRect(gfx::Rect(0, 1, w - 1, h - 2), background); |
| 223 background_color(state)); | 219 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border); |
| 224 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border_color(state)); | 220 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); |
| 225 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color(state)); | 221 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); |
| 226 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color(state)); | 222 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); |
| 227 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color(state)); | 223 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border); |
| 228 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border_color(state)); | |
| 229 break; | 224 break; |
| 230 | 225 |
| 231 case SINGLE_BUTTON: | 226 case SINGLE_BUTTON: |
| 232 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), | 227 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); |
| 233 background_color(state)); | 228 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border); |
| 234 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border_color(state)); | 229 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); |
| 235 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color(state)); | 230 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); |
| 236 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color(state)); | 231 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); |
| 237 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color(state)); | 232 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border); |
| 238 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border_color(state)); | 233 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); |
| 239 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color(state)); | 234 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); |
| 240 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color(state)); | 235 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); |
| 241 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color(state)); | |
| 242 break; | 236 break; |
| 243 | 237 |
| 244 default: | 238 default: |
| 245 NOTREACHED(); | 239 NOTREACHED(); |
| 246 break; | 240 break; |
| 247 } | 241 } |
| 248 } | 242 } |
| 249 | 243 |
| 250 private: | 244 private: |
| 251 static SkColor border_color(CustomButton::ButtonState state) { | 245 static SkColor border_color(View* view, CustomButton::ButtonState state) { |
| 246 ui::NativeTheme *theme = view->GetNativeTheme(); | |
| 252 switch (state) { | 247 switch (state) { |
| 253 case CustomButton::STATE_HOVERED: return kHotBorderColor; | 248 case CustomButton::STATE_HOVERED: |
| 254 case CustomButton::STATE_PRESSED: return kPushedBorderColor; | 249 return theme->GetSystemColor( |
| 255 default: return kBorderColor; | 250 ui::NativeTheme::kColorId_HoverMenuItemBorderColor); |
|
sky
2013/03/19 21:08:26
indent 4 here, 253 and all other similar places.
Bobby Powers
2013/03/20 14:54:38
Done.
| |
| 251 case CustomButton::STATE_PRESSED: | |
| 252 return theme->GetSystemColor( | |
| 253 ui::NativeTheme::kColorId_FocusedMenuItemBorderColor); | |
| 254 default: | |
| 255 return theme->GetSystemColor( | |
| 256 ui::NativeTheme::kColorId_EnabledMenuItemBorderColor); | |
| 256 } | 257 } |
| 257 } | 258 } |
| 258 | 259 |
| 259 static SkColor background_color(CustomButton::ButtonState state) { | 260 static SkColor background_color(View* view, CustomButton::ButtonState state) { |
| 261 ui::NativeTheme *theme = view->GetNativeTheme(); | |
| 260 switch (state) { | 262 switch (state) { |
| 261 case CustomButton::STATE_HOVERED: return kHotBackgroundColor; | 263 case CustomButton::STATE_HOVERED: |
| 262 case CustomButton::STATE_PRESSED: return kPushedBackgroundColor; | 264 return theme->GetSystemColor( |
| 263 default: return kBackgroundColor; | 265 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); |
| 266 case CustomButton::STATE_PRESSED: | |
| 267 return theme->GetSystemColor( | |
| 268 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | |
| 269 default: | |
| 270 return theme->GetSystemColor( | |
| 271 ui::NativeTheme::kColorId_MenuBackgroundColor); | |
| 264 } | 272 } |
| 265 } | 273 } |
| 266 | 274 |
| 267 static SkColor touch_background_color(CustomButton::ButtonState state) { | 275 static SkColor touch_background_color(CustomButton::ButtonState state) { |
| 268 switch (state) { | 276 switch (state) { |
| 269 case CustomButton::STATE_HOVERED: return kHotTouchBackgroundColor; | 277 case CustomButton::STATE_HOVERED: return kHoverTouchBackgroundColor; |
| 270 case CustomButton::STATE_PRESSED: return kPushedTouchBackgroundColor; | 278 case CustomButton::STATE_PRESSED: return kFocusedTouchBackgroundColor; |
| 271 default: return kTouchBackgroundColor; | 279 default: return kEnabledTouchBackgroundColor; |
| 272 } | 280 } |
| 273 } | 281 } |
| 274 | 282 |
| 275 ButtonType TypeAdjustedForRTL() const { | 283 ButtonType TypeAdjustedForRTL() const { |
| 276 if (!base::i18n::IsRTL()) | 284 if (!base::i18n::IsRTL()) |
| 277 return type_; | 285 return type_; |
| 278 | 286 |
| 279 switch (type_) { | 287 switch (type_) { |
| 280 case LEFT_BUTTON: return RIGHT_BUTTON; | 288 case LEFT_BUTTON: return RIGHT_BUTTON; |
| 281 case RIGHT_BUTTON: return LEFT_BUTTON; | 289 case RIGHT_BUTTON: return LEFT_BUTTON; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 | 411 |
| 404 } // namespace | 412 } // namespace |
| 405 | 413 |
| 406 // CutCopyPasteView ------------------------------------------------------------ | 414 // CutCopyPasteView ------------------------------------------------------------ |
| 407 | 415 |
| 408 // CutCopyPasteView is the view containing the cut/copy/paste buttons. | 416 // CutCopyPasteView is the view containing the cut/copy/paste buttons. |
| 409 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { | 417 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
| 410 public: | 418 public: |
| 411 CutCopyPasteView(WrenchMenu* menu, | 419 CutCopyPasteView(WrenchMenu* menu, |
| 412 MenuModel* menu_model, | 420 MenuModel* menu_model, |
| 421 View* menu_view, | |
| 413 int cut_index, | 422 int cut_index, |
| 414 int copy_index, | 423 int copy_index, |
| 415 int paste_index) | 424 int paste_index) |
| 416 : WrenchMenuView(menu, menu_model) { | 425 : WrenchMenuView(menu, menu_model) { |
| 417 LabelButton* cut = CreateAndConfigureButton( | 426 LabelButton* cut = CreateAndConfigureButton( |
| 418 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); | 427 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); |
| 419 | 428 |
| 420 MenuButtonBackground* copy_background = NULL; | 429 MenuButtonBackground* copy_background = NULL; |
| 421 LabelButton* copy = CreateAndConfigureButton( | 430 LabelButton* copy = CreateAndConfigureButton( |
| 422 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, | 431 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, |
| 423 ©_background); | 432 ©_background); |
| 424 | 433 |
| 425 LabelButton* paste = CreateAndConfigureButton( | 434 LabelButton* paste = CreateAndConfigureButton( |
| 426 IDS_PASTE, | 435 IDS_PASTE, |
| 427 menu_->use_new_menu() && menu_->supports_new_separators_ ? | 436 menu_->use_new_menu() && menu_->supports_new_separators_ ? |
| 428 MenuButtonBackground::CENTER_BUTTON : | 437 MenuButtonBackground::CENTER_BUTTON : |
| 429 MenuButtonBackground::RIGHT_BUTTON, | 438 MenuButtonBackground::RIGHT_BUTTON, |
| 430 paste_index, | 439 paste_index, |
| 431 NULL); | 440 NULL); |
| 432 if (menu_->use_new_menu()) { | 441 if (menu_->use_new_menu()) { |
| 433 cut->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | 442 cut->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); |
| 434 copy->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | 443 copy->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); |
| 435 paste->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | 444 paste->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); |
| 436 } else { | 445 } else { |
| 437 SkColor text_color = GetNativeTheme()->GetSystemColor( | 446 SkColor text_color = menu_view->GetNativeTheme()->GetSystemColor( |
| 438 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | 447 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
| 439 cut->SetTextColor(views::Button::STATE_NORMAL, text_color); | 448 cut->SetTextColor(views::Button::STATE_NORMAL, text_color); |
| 440 copy->SetTextColor(views::Button::STATE_NORMAL, text_color); | 449 copy->SetTextColor(views::Button::STATE_NORMAL, text_color); |
| 441 paste->SetTextColor(views::Button::STATE_NORMAL, text_color); | 450 paste->SetTextColor(views::Button::STATE_NORMAL, text_color); |
| 442 } | 451 } |
| 443 copy_background->SetOtherButtons(cut, paste); | 452 copy_background->SetOtherButtons(cut, paste); |
| 444 } | 453 } |
| 445 | 454 |
| 446 // Overridden from View. | 455 // Overridden from View. |
| 447 virtual gfx::Size GetPreferredSize() OVERRIDE { | 456 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 static const int kZoomPadding = 6; | 490 static const int kZoomPadding = 6; |
| 482 static const int kTouchZoomPadding = 14; | 491 static const int kTouchZoomPadding = 14; |
| 483 | 492 |
| 484 // ZoomView contains the various zoom controls: two buttons to increase/decrease | 493 // ZoomView contains the various zoom controls: two buttons to increase/decrease |
| 485 // the zoom, a label showing the current zoom percent, and a button to go | 494 // the zoom, a label showing the current zoom percent, and a button to go |
| 486 // full-screen. | 495 // full-screen. |
| 487 class WrenchMenu::ZoomView : public WrenchMenuView { | 496 class WrenchMenu::ZoomView : public WrenchMenuView { |
| 488 public: | 497 public: |
| 489 ZoomView(WrenchMenu* menu, | 498 ZoomView(WrenchMenu* menu, |
| 490 MenuModel* menu_model, | 499 MenuModel* menu_model, |
| 500 View* menu_view, | |
| 491 int decrement_index, | 501 int decrement_index, |
| 492 int increment_index, | 502 int increment_index, |
| 493 int fullscreen_index) | 503 int fullscreen_index) |
| 494 : WrenchMenuView(menu, menu_model), | 504 : WrenchMenuView(menu, menu_model), |
| 495 fullscreen_index_(fullscreen_index), | 505 fullscreen_index_(fullscreen_index), |
| 496 zoom_callback_(base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, | 506 zoom_callback_(base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, |
| 497 base::Unretained(this))), | 507 base::Unretained(this))), |
| 498 increment_button_(NULL), | 508 increment_button_(NULL), |
| 499 zoom_label_(NULL), | 509 zoom_label_(NULL), |
| 500 decrement_button_(NULL), | 510 decrement_button_(NULL), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 548 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 539 IDR_FULLSCREEN_MENU_BUTTON); | 549 IDR_FULLSCREEN_MENU_BUTTON); |
| 540 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); | 550 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
| 541 if (menu_->use_new_menu()) { | 551 if (menu_->use_new_menu()) { |
| 542 zoom_label_->SetEnabledColor(kTouchButtonText); | 552 zoom_label_->SetEnabledColor(kTouchButtonText); |
| 543 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | 553 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 544 kTouchButtonText); | 554 kTouchButtonText); |
| 545 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | 555 increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 546 kTouchButtonText); | 556 kTouchButtonText); |
| 547 } else { | 557 } else { |
| 548 SkColor enabled_text_color = GetNativeTheme()->GetSystemColor( | 558 SkColor enabled_text_color = menu_view->GetNativeTheme()->GetSystemColor( |
| 549 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | 559 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
| 550 zoom_label_->SetEnabledColor(enabled_text_color); | 560 zoom_label_->SetEnabledColor(enabled_text_color); |
| 551 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | 561 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 552 enabled_text_color); | 562 enabled_text_color); |
| 553 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | 563 increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 554 enabled_text_color); | 564 enabled_text_color); |
| 555 SkColor disabled_text_color = GetNativeTheme()->GetSystemColor( | 565 SkColor disabled_text_color = menu_view->GetNativeTheme()->GetSystemColor( |
| 556 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); | 566 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
| 557 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, | 567 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, |
| 558 disabled_text_color); | 568 disabled_text_color); |
| 559 increment_button_->SetTextColor(views::Button::STATE_DISABLED, | 569 increment_button_->SetTextColor(views::Button::STATE_DISABLED, |
| 560 disabled_text_color); | 570 disabled_text_color); |
| 561 } | 571 } |
| 562 | 572 |
| 563 fullscreen_button_->set_focusable(true); | 573 fullscreen_button_->set_focusable(true); |
| 564 fullscreen_button_->set_request_focus_on_press(false); | 574 fullscreen_button_->set_request_focus_on_press(false); |
| 565 fullscreen_button_->set_tag(fullscreen_index); | 575 fullscreen_button_->set_tag(fullscreen_index); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 | 789 |
| 780 WrenchMenu::~WrenchMenu() { | 790 WrenchMenu::~WrenchMenu() { |
| 781 if (bookmark_menu_delegate_.get()) { | 791 if (bookmark_menu_delegate_.get()) { |
| 782 BookmarkModel* model = BookmarkModelFactory::GetForProfile( | 792 BookmarkModel* model = BookmarkModelFactory::GetForProfile( |
| 783 browser_->profile()); | 793 browser_->profile()); |
| 784 if (model) | 794 if (model) |
| 785 model->RemoveObserver(this); | 795 model->RemoveObserver(this); |
| 786 } | 796 } |
| 787 } | 797 } |
| 788 | 798 |
| 789 void WrenchMenu::Init(ui::MenuModel* model) { | 799 void WrenchMenu::Init(View* view, ui::MenuModel* model) { |
| 790 DCHECK(!root_); | 800 DCHECK(!root_); |
| 791 root_ = new MenuItemView(this); | 801 root_ = new MenuItemView(this); |
| 792 root_->set_has_icons(true); // We have checks, radios and icons, set this | 802 root_->set_has_icons(true); // We have checks, radios and icons, set this |
| 793 // so we get the taller menu style. | 803 // so we get the taller menu style. |
| 794 int next_id = 1; | 804 int next_id = 1; |
| 795 PopulateMenu(root_, model, &next_id); | 805 PopulateMenu(root_, model, view, &next_id); |
| 796 first_bookmark_command_id_ = next_id + 1; | 806 first_bookmark_command_id_ = next_id + 1; |
| 797 menu_runner_.reset(new views::MenuRunner(root_)); | 807 menu_runner_.reset(new views::MenuRunner(root_)); |
| 798 } | 808 } |
| 799 | 809 |
| 800 void WrenchMenu::RunMenu(views::MenuButton* host) { | 810 void WrenchMenu::RunMenu(views::MenuButton* host) { |
| 801 gfx::Point screen_loc; | 811 gfx::Point screen_loc; |
| 802 views::View::ConvertPointToScreen(host, &screen_loc); | 812 views::View::ConvertPointToScreen(host, &screen_loc); |
| 803 gfx::Rect bounds(screen_loc, host->size()); | 813 gfx::Rect bounds(screen_loc, host->size()); |
| 804 content::RecordAction(UserMetricsAction("ShowAppMenu")); | 814 content::RecordAction(UserMetricsAction("ShowAppMenu")); |
| 805 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, | 815 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 // menu. Close the menu to avoid have a stale menu on-screen. | 1035 // menu. Close the menu to avoid have a stale menu on-screen. |
| 1026 root_->Cancel(); | 1036 root_->Cancel(); |
| 1027 break; | 1037 break; |
| 1028 default: | 1038 default: |
| 1029 NOTREACHED(); | 1039 NOTREACHED(); |
| 1030 } | 1040 } |
| 1031 } | 1041 } |
| 1032 | 1042 |
| 1033 void WrenchMenu::PopulateMenu(MenuItemView* parent, | 1043 void WrenchMenu::PopulateMenu(MenuItemView* parent, |
| 1034 MenuModel* model, | 1044 MenuModel* model, |
| 1045 View* view, | |
| 1035 int* next_id) { | 1046 int* next_id) { |
| 1036 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { | 1047 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { |
| 1037 // The button container menu items have a special height which we have to | 1048 // The button container menu items have a special height which we have to |
| 1038 // use instead of the normal height. | 1049 // use instead of the normal height. |
| 1039 int height = 0; | 1050 int height = 0; |
| 1040 if (use_new_menu_ && | 1051 if (use_new_menu_ && |
| 1041 (model->GetCommandIdAt(i) == IDC_CUT || | 1052 (model->GetCommandIdAt(i) == IDC_CUT || |
| 1042 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) | 1053 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) |
| 1043 height = kMenuItemContainingButtonsHeight; | 1054 height = kMenuItemContainingButtonsHeight; |
| 1044 | 1055 |
| 1045 MenuItemView* item = AppendMenuItem( | 1056 MenuItemView* item = AppendMenuItem( |
| 1046 parent, model, i, model->GetTypeAt(i), next_id, height); | 1057 parent, model, i, model->GetTypeAt(i), next_id, height); |
| 1047 | 1058 |
| 1048 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) | 1059 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) |
| 1049 PopulateMenu(item, model->GetSubmenuModelAt(i), next_id); | 1060 PopulateMenu(item, model->GetSubmenuModelAt(i), view, next_id); |
| 1050 | 1061 |
| 1051 switch (model->GetCommandIdAt(i)) { | 1062 switch (model->GetCommandIdAt(i)) { |
| 1052 case IDC_CUT: | 1063 case IDC_CUT: |
| 1053 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1064 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
| 1054 DCHECK_LT(i + 2, max); | 1065 DCHECK_LT(i + 2, max); |
| 1055 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); | 1066 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); |
| 1056 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); | 1067 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); |
| 1057 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); | 1068 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); |
| 1058 item->AddChildView(new CutCopyPasteView(this, model, i, i + 1, i + 2)); | 1069 item->AddChildView(new CutCopyPasteView(this, model, view, |
| 1070 i, i + 1, i + 2)); | |
| 1059 i += 2; | 1071 i += 2; |
| 1060 break; | 1072 break; |
| 1061 | 1073 |
| 1062 case IDC_ZOOM_MINUS: | 1074 case IDC_ZOOM_MINUS: |
| 1063 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1075 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
| 1064 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1)); | 1076 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1)); |
| 1065 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2)); | 1077 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2)); |
| 1066 item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2)); | 1078 item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2)); |
| 1067 item->AddChildView(new ZoomView(this, model, i, i + 1, i + 2)); | 1079 item->AddChildView(new ZoomView(this, model, view, |
| 1080 i, i + 1, i + 2)); | |
| 1068 i += 2; | 1081 i += 2; |
| 1069 break; | 1082 break; |
| 1070 | 1083 |
| 1071 case IDC_BOOKMARKS_MENU: | 1084 case IDC_BOOKMARKS_MENU: |
| 1072 DCHECK(!bookmark_menu_); | 1085 DCHECK(!bookmark_menu_); |
| 1073 bookmark_menu_ = item; | 1086 bookmark_menu_ = item; |
| 1074 break; | 1087 break; |
| 1075 | 1088 |
| 1076 case IDC_FEEDBACK: | 1089 case IDC_FEEDBACK: |
| 1077 DCHECK(!feedback_menu_item_); | 1090 DCHECK(!feedback_menu_item_); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 bookmark_menu_delegate_.reset( | 1164 bookmark_menu_delegate_.reset( |
| 1152 new BookmarkMenuDelegate(browser_, | 1165 new BookmarkMenuDelegate(browser_, |
| 1153 browser_, | 1166 browser_, |
| 1154 parent, | 1167 parent, |
| 1155 first_bookmark_command_id_)); | 1168 first_bookmark_command_id_)); |
| 1156 bookmark_menu_delegate_->Init( | 1169 bookmark_menu_delegate_->Init( |
| 1157 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1170 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
| 1158 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1171 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1159 bookmark_utils::LAUNCH_WRENCH_MENU); | 1172 bookmark_utils::LAUNCH_WRENCH_MENU); |
| 1160 } | 1173 } |
| OLD | NEW |