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

Side by Side Diff: chrome/browser/ui/views/wrench_menu.cc

Issue 10837317: Setting the touch wrench menu as default menu for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed second review Created 8 years, 4 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) 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const SkColor kBorderColor = SkColorSetARGB(36, 0, 0, 0); 70 const SkColor kBorderColor = SkColorSetARGB(36, 0, 0, 0);
71 const SkColor kPushedBorderColor = SkColorSetARGB(72, 0, 0, 0); 71 const SkColor kPushedBorderColor = SkColorSetARGB(72, 0, 0, 0);
72 const SkColor kHotBackgroundColor = SkColorSetARGB(204, 255, 255, 255); 72 const SkColor kHotBackgroundColor = SkColorSetARGB(204, 255, 255, 255);
73 const SkColor kBackgroundColor = SkColorSetARGB(102, 255, 255, 255); 73 const SkColor kBackgroundColor = SkColorSetARGB(102, 255, 255, 255);
74 const SkColor kPushedBackgroundColor = SkColorSetARGB(13, 0, 0, 0); 74 const SkColor kPushedBackgroundColor = SkColorSetARGB(13, 0, 0, 0);
75 const SkColor kTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); 75 const SkColor kTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255);
76 const SkColor kHotTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); 76 const SkColor kHotTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242);
77 const SkColor kPushedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); 77 const SkColor kPushedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235);
78 78
79 const SkColor kTouchButtonText = 0xff5a5a5a; 79 const SkColor kTouchButtonText = 0xff5a5a5a;
80 const SkColor kTouchImageBrighten = 0x80ffffff;
81 80
82 // Horizontal padding on the edges of the buttons. 81 // Horizontal padding on the edges of the buttons.
83 const int kHorizontalPadding = 6; 82 const int kHorizontalPadding = 6;
84 // Horizontal padding for a touch enabled menu. 83 // Horizontal padding for a touch enabled menu.
85 const int kHorizontalTouchPadding = 15; 84 const int kHorizontalTouchPadding = 15;
86 85
87 // For touch menu items we want to have this height in pixels. 86 // For touch menu items we want to have this height in pixels.
88 const int kTouchItemHeight = 47; 87 const int kTouchItemHeight = 43;
89 88
90 // Subclass of ImageButton whose preferred size includes the size of the border. 89 // Subclass of ImageButton whose preferred size includes the size of the border.
91 class FullscreenButton : public ImageButton { 90 class FullscreenButton : public ImageButton {
92 public: 91 public:
93 explicit FullscreenButton(views::ButtonListener* listener) 92 explicit FullscreenButton(views::ButtonListener* listener)
94 : ImageButton(listener) { } 93 : ImageButton(listener) { }
95 94
96 // Overridden from ImageButton. 95 // Overridden from ImageButton.
97 virtual gfx::Size GetPreferredSize() OVERRIDE { 96 virtual gfx::Size GetPreferredSize() OVERRIDE {
98 gfx::Size pref = ImageButton::GetPreferredSize(); 97 gfx::Size pref = ImageButton::GetPreferredSize();
99 gfx::Insets insets; 98 gfx::Insets insets;
100 if (border()) 99 if (border())
101 border()->GetInsets(&insets); 100 border()->GetInsets(&insets);
102 pref.Enlarge(insets.width(), insets.height()); 101 pref.Enlarge(insets.width(), insets.height());
103 return pref; 102 return pref;
104 } 103 }
105 104
106 private: 105 private:
107 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); 106 DISALLOW_COPY_AND_ASSIGN(FullscreenButton);
108 }; 107 };
109 108
110 // Border for buttons contained in the menu. This is only used for getting the 109 // Border for buttons contained in the menu. This is only used for getting the
111 // insets, the actual painting is done in MenuButtonBackground. 110 // insets, the actual painting is done in MenuButtonBackground.
112 class MenuButtonBorder : public views::Border { 111 class MenuButtonBorder : public views::Border {
113 public: 112 public:
114 MenuButtonBorder() 113 MenuButtonBorder()
115 : horizontal_padding_(ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? 114 : horizontal_padding_(MenuConfig::IsNewMenu() ?
116 kHorizontalTouchPadding : 115 kHorizontalTouchPadding :
117 kHorizontalPadding) {} 116 kHorizontalPadding) {}
118 117
119 // Overridden from views::Border. 118 // Overridden from views::Border.
120 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE { 119 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE {
121 // Painting of border is done in MenuButtonBackground. 120 // Painting of border is done in MenuButtonBackground.
122 } 121 }
123 122
124 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE { 123 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE {
125 insets->Set(MenuConfig::instance().item_top_margin, 124 insets->Set(MenuConfig::instance().item_top_margin,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // Overridden from views::Background. 166 // Overridden from views::Background.
168 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { 167 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE {
169 CustomButton::ButtonState state = 168 CustomButton::ButtonState state =
170 (view->GetClassName() == views::Label::kViewClassName) ? 169 (view->GetClassName() == views::Label::kViewClassName) ?
171 CustomButton::BS_NORMAL : static_cast<CustomButton*>(view)->state(); 170 CustomButton::BS_NORMAL : static_cast<CustomButton*>(view)->state();
172 int w = view->width(); 171 int w = view->width();
173 int h = view->height(); 172 int h = view->height();
174 // Windows is drawing its own separators and we cannot use the touch button 173 // Windows is drawing its own separators and we cannot use the touch button
175 // for that. 174 // for that.
176 #if !defined(OS_WIN) 175 #if !defined(OS_WIN)
177 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { 176 if (MenuConfig::IsNewMenu()) {
178 // 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
179 // 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
180 // buttons. 179 // buttons.
181 int border = 0; 180 int border = 0;
182 if (type_ != RIGHT_BUTTON) { 181 if (type_ != RIGHT_BUTTON) {
183 border = 1; 182 border = 1;
184 canvas->FillRect(gfx::Rect(0, 0, border, h), 183 canvas->FillRect(gfx::Rect(0, 0, border, h),
185 border_color(CustomButton::BS_NORMAL)); 184 border_color(CustomButton::BS_NORMAL));
186 } 185 }
187 canvas->FillRect(gfx::Rect(border, 0, w - border, h), 186 canvas->FillRect(gfx::Rect(border, 0, w - border, h),
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 size.set_height(height); 393 size.set_height(height);
395 return size; 394 return size;
396 } 395 }
397 396
398 private: 397 private:
399 int height_; 398 int height_;
400 399
401 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); 400 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView);
402 }; 401 };
403 402
404 class TintedImageSource: public gfx::CanvasImageSource {
405 public:
406 TintedImageSource(gfx::ImageSkia& image, SkColor tint_value)
407 : CanvasImageSource(image.size(), false),
408 image_(image),
409 tint_value_(tint_value) {
410 }
411
412 virtual ~TintedImageSource() {
413 }
414
415 // Overridden from gfx::CanvasImageSource.
416 virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
417 canvas->DrawImageInt(image_, 0, 0);
418 SkPaint paint;
419 // We leave the old alpha alone and add the new color multiplied
420 // with the source alpha to the existing alpha. Thus: We brighten
421 // the image up - but only the non transparent pixels.
422 paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
423 paint.setColor(tint_value_);
424 canvas->sk_canvas()->drawPaint(paint);
425 }
426
427 private:
428 const gfx::ImageSkia image_;
429 const SkColor tint_value_;
430
431 DISALLOW_COPY_AND_ASSIGN(TintedImageSource);
432 };
433
434 } // namespace 403 } // namespace
435 404
436 // CutCopyPasteView ------------------------------------------------------------ 405 // CutCopyPasteView ------------------------------------------------------------
437 406
438 // CutCopyPasteView is the view containing the cut/copy/paste buttons. 407 // CutCopyPasteView is the view containing the cut/copy/paste buttons.
439 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { 408 class WrenchMenu::CutCopyPasteView : public WrenchMenuView {
440 public: 409 public:
441 CutCopyPasteView(WrenchMenu* menu, 410 CutCopyPasteView(WrenchMenu* menu,
442 MenuModel* menu_model, 411 MenuModel* menu_model,
443 int cut_index, 412 int cut_index,
444 int copy_index, 413 int copy_index,
445 int paste_index) 414 int paste_index)
446 : WrenchMenuView(menu, menu_model) { 415 : WrenchMenuView(menu, menu_model) {
447 TextButton* cut = CreateAndConfigureButton( 416 TextButton* cut = CreateAndConfigureButton(
448 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); 417 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL);
449 418
450 MenuButtonBackground* copy_background = NULL; 419 MenuButtonBackground* copy_background = NULL;
451 TextButton* copy = CreateAndConfigureButton( 420 TextButton* copy = CreateAndConfigureButton(
452 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, 421 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index,
453 &copy_background); 422 &copy_background);
454 423
455 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 424 bool is_new_menu = MenuConfig::IsNewMenu();
456 425
457 TextButton* paste = CreateAndConfigureButton( 426 TextButton* paste = CreateAndConfigureButton(
458 IDS_PASTE, 427 IDS_PASTE,
459 #if !defined(OS_WIN) 428 #if !defined(OS_WIN)
460 is_touch ? MenuButtonBackground::CENTER_BUTTON : 429 is_new_menu ? MenuButtonBackground::CENTER_BUTTON :
461 #endif 430 #endif
462 MenuButtonBackground::RIGHT_BUTTON, 431 MenuButtonBackground::RIGHT_BUTTON,
463 paste_index, 432 paste_index,
464 NULL); 433 NULL);
465 if (is_touch) { 434 if (is_new_menu) {
466 cut->SetEnabledColor(kTouchButtonText); 435 cut->SetEnabledColor(kTouchButtonText);
467 copy->SetEnabledColor(kTouchButtonText); 436 copy->SetEnabledColor(kTouchButtonText);
468 paste->SetEnabledColor(kTouchButtonText); 437 paste->SetEnabledColor(kTouchButtonText);
469 } 438 }
470 copy_background->SetOtherButtons(cut, paste); 439 copy_background->SetOtherButtons(cut, paste);
471 } 440 }
472 441
473 // Overridden from View. 442 // Overridden from View.
474 virtual gfx::Size GetPreferredSize() OVERRIDE { 443 virtual gfx::Size GetPreferredSize() OVERRIDE {
475 // Returned height doesn't matter as MenuItemView forces everything to the 444 // Returned height doesn't matter as MenuItemView forces everything to the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 zoom_label_width_(0) { 497 zoom_label_width_(0) {
529 decrement_button_ = CreateButtonWithAccName( 498 decrement_button_ = CreateButtonWithAccName(
530 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, 499 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index,
531 NULL, IDS_ACCNAME_ZOOM_MINUS2); 500 NULL, IDS_ACCNAME_ZOOM_MINUS2);
532 501
533 zoom_label_ = new Label( 502 zoom_label_ = new Label(
534 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 503 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
535 zoom_label_->SetAutoColorReadabilityEnabled(false); 504 zoom_label_->SetAutoColorReadabilityEnabled(false);
536 zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT); 505 zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT);
537 506
538 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 507 bool is_new_menu = MenuConfig::IsNewMenu();
539 508
540 MenuButtonBackground* center_bg = new MenuButtonBackground( 509 MenuButtonBackground* center_bg = new MenuButtonBackground(
541 #if !defined(OS_WIN) 510 #if !defined(OS_WIN)
542 is_touch ? MenuButtonBackground::RIGHT_BUTTON : 511 is_new_menu ? MenuButtonBackground::RIGHT_BUTTON :
543 #endif 512 #endif
544 MenuButtonBackground::CENTER_BUTTON); 513 MenuButtonBackground::CENTER_BUTTON);
545 zoom_label_->set_background(center_bg); 514 zoom_label_->set_background(center_bg);
546 zoom_label_->set_border(new MenuButtonBorder()); 515 zoom_label_->set_border(new MenuButtonBorder());
547 zoom_label_->SetFont(MenuConfig::instance().font); 516 zoom_label_->SetFont(MenuConfig::instance().font);
548 517
549 AddChildView(zoom_label_); 518 AddChildView(zoom_label_);
550 zoom_label_width_ = MaxWidthForZoomLabel(); 519 zoom_label_width_ = MaxWidthForZoomLabel();
551 520
552 increment_button_ = CreateButtonWithAccName( 521 increment_button_ = CreateButtonWithAccName(
553 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, 522 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index,
554 NULL, IDS_ACCNAME_ZOOM_PLUS2); 523 NULL, IDS_ACCNAME_ZOOM_PLUS2);
555 524
556 center_bg->SetOtherButtons(decrement_button_, increment_button_); 525 center_bg->SetOtherButtons(decrement_button_, increment_button_);
557 526
558 fullscreen_button_ = new FullscreenButton(this); 527 fullscreen_button_ = new FullscreenButton(this);
559 gfx::ImageSkia* full_screen_image = 528 gfx::ImageSkia* full_screen_image =
560 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 529 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
561 IDR_FULLSCREEN_MENU_BUTTON); 530 IDR_FULLSCREEN_MENU_BUTTON);
562 if (is_touch) { 531 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image);
563 // In case of touch, the menu needs to be brightened up a bit. 532 if (is_new_menu) {
564 gfx::CanvasImageSource* source = new TintedImageSource(
565 *full_screen_image, kTouchImageBrighten);
566 // ImageSkia takes ownership of |source|.
567 tinted_fullscreen_image_ = gfx::ImageSkia(source, source->size());
568 fullscreen_button_->SetImage(ImageButton::BS_NORMAL,
569 &tinted_fullscreen_image_);
570 } else {
571 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image);
572 }
573 if (is_touch) {
574 zoom_label_->SetEnabledColor(kTouchButtonText); 533 zoom_label_->SetEnabledColor(kTouchButtonText);
575 decrement_button_->SetEnabledColor(kTouchButtonText); 534 decrement_button_->SetEnabledColor(kTouchButtonText);
576 increment_button_->SetEnabledColor(kTouchButtonText); 535 increment_button_->SetEnabledColor(kTouchButtonText);
577 } else { 536 } else {
578 zoom_label_->SetEnabledColor(MenuConfig::instance().text_color); 537 zoom_label_->SetEnabledColor(MenuConfig::instance().text_color);
579 } 538 }
580 539
581 fullscreen_button_->set_focusable(true); 540 fullscreen_button_->set_focusable(true);
582 fullscreen_button_->set_request_focus_on_press(false); 541 fullscreen_button_->set_request_focus_on_press(false);
583 fullscreen_button_->set_tag(fullscreen_index); 542 fullscreen_button_->set_tag(fullscreen_index);
584 fullscreen_button_->SetImageAlignment( 543 fullscreen_button_->SetImageAlignment(
585 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); 544 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
586 int horizontal_padding = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? 545 int horizontal_padding = MenuConfig::IsNewMenu() ?
587 kHorizontalTouchPadding : kHorizontalPadding; 546 kHorizontalTouchPadding : kHorizontalPadding;
588 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( 547 fullscreen_button_->set_border(views::Border::CreateEmptyBorder(
589 0, horizontal_padding, 0, horizontal_padding)); 548 0, horizontal_padding, 0, horizontal_padding));
590 fullscreen_button_->set_background( 549 fullscreen_button_->set_background(
591 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON)); 550 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON));
592 fullscreen_button_->SetAccessibleName( 551 fullscreen_button_->SetAccessibleName(
593 GetAccessibleNameForWrenchMenuItem( 552 GetAccessibleNameForWrenchMenuItem(
594 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); 553 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
595 AddChildView(fullscreen_button_); 554 AddChildView(fullscreen_button_);
596 555
597 UpdateZoomControls(); 556 UpdateZoomControls();
598 557
599 registrar_.Add( 558 registrar_.Add(
600 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 559 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
601 content::Source<HostZoomMap>( 560 content::Source<HostZoomMap>(
602 HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); 561 HostZoomMap::GetForBrowserContext(menu->browser_->profile())));
603 } 562 }
604 563
605 // Overridden from View. 564 // Overridden from View.
606 virtual gfx::Size GetPreferredSize() OVERRIDE { 565 virtual gfx::Size GetPreferredSize() OVERRIDE {
607 // The increment/decrement button are forced to the same width. 566 // The increment/decrement button are forced to the same width.
608 int button_width = std::max(increment_button_->GetPreferredSize().width(), 567 int button_width = std::max(increment_button_->GetPreferredSize().width(),
609 decrement_button_->GetPreferredSize().width()); 568 decrement_button_->GetPreferredSize().width());
610 int zoom_padding = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? 569 int zoom_padding = MenuConfig::IsNewMenu() ? kTouchZoomPadding :
611 kTouchZoomPadding : kZoomPadding; 570 kZoomPadding;
612 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + 571 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() +
613 zoom_padding; 572 zoom_padding;
614 // Returned height doesn't matter as MenuItemView forces everything to the 573 // Returned height doesn't matter as MenuItemView forces everything to the
615 // height of the menuitemview. Note that we have overridden the height when 574 // height of the menuitemview. Note that we have overridden the height when
616 // constructing the menu. 575 // constructing the menu.
617 return gfx::Size(button_width + zoom_label_width_ + button_width + 576 return gfx::Size(button_width + zoom_label_width_ + button_width +
618 fullscreen_width, 0); 577 fullscreen_width, 0);
619 } 578 }
620 579
621 virtual void Layout() OVERRIDE { 580 virtual void Layout() OVERRIDE {
622 int x = 0; 581 int x = 0;
623 int button_width = std::max(increment_button_->GetPreferredSize().width(), 582 int button_width = std::max(increment_button_->GetPreferredSize().width(),
624 decrement_button_->GetPreferredSize().width()); 583 decrement_button_->GetPreferredSize().width());
625 gfx::Rect bounds(0, 0, button_width, height()); 584 gfx::Rect bounds(0, 0, button_width, height());
626 585
627 decrement_button_->SetBoundsRect(bounds); 586 decrement_button_->SetBoundsRect(bounds);
628 587
629 x += bounds.width(); 588 x += bounds.width();
630 bounds.set_x(x); 589 bounds.set_x(x);
631 bounds.set_width(zoom_label_width_); 590 bounds.set_width(zoom_label_width_);
632 zoom_label_->SetBoundsRect(bounds); 591 zoom_label_->SetBoundsRect(bounds);
633 592
634 x += bounds.width(); 593 x += bounds.width();
635 bounds.set_x(x); 594 bounds.set_x(x);
636 bounds.set_width(button_width); 595 bounds.set_width(button_width);
637 increment_button_->SetBoundsRect(bounds); 596 increment_button_->SetBoundsRect(bounds);
638 597
639 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 598 bool is_new_menu = MenuConfig::IsNewMenu();
640 x += bounds.width() + (is_touch ? 0 : kZoomPadding); 599 x += bounds.width() + (is_new_menu ? 0 : kZoomPadding);
641 bounds.set_x(x); 600 bounds.set_x(x);
642 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + 601 bounds.set_width(fullscreen_button_->GetPreferredSize().width() +
643 (is_touch ? kTouchZoomPadding : 0)); 602 (is_new_menu ? kTouchZoomPadding : 0));
644 fullscreen_button_->SetBoundsRect(bounds); 603 fullscreen_button_->SetBoundsRect(bounds);
645 } 604 }
646 605
647 // Overridden from ButtonListener. 606 // Overridden from ButtonListener.
648 virtual void ButtonPressed(views::Button* sender, 607 virtual void ButtonPressed(views::Button* sender,
649 const ui::Event& event) OVERRIDE { 608 const ui::Event& event) OVERRIDE {
650 if (sender->tag() == fullscreen_index_) { 609 if (sender->tag() == fullscreen_index_) {
651 menu_->CancelAndEvaluate(menu_model_, sender->tag()); 610 menu_->CancelAndEvaluate(menu_model_, sender->tag());
652 } else { 611 } else {
653 // Zoom buttons don't close the menu. 612 // Zoom buttons don't close the menu.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 TextButton* increment_button_; 686 TextButton* increment_button_;
728 687
729 // Label showing zoom as a percent. 688 // Label showing zoom as a percent.
730 Label* zoom_label_; 689 Label* zoom_label_;
731 690
732 // Button for decrementing the zoom. 691 // Button for decrementing the zoom.
733 TextButton* decrement_button_; 692 TextButton* decrement_button_;
734 693
735 ImageButton* fullscreen_button_; 694 ImageButton* fullscreen_button_;
736 695
737 // The tinted bitmap of the fullscreen button.
738 gfx::ImageSkia tinted_fullscreen_image_;
739
740 // Width given to |zoom_label_|. This is the width at 100%. 696 // Width given to |zoom_label_|. This is the width at 100%.
741 int zoom_label_width_; 697 int zoom_label_width_;
742 698
743 DISALLOW_COPY_AND_ASSIGN(ZoomView); 699 DISALLOW_COPY_AND_ASSIGN(ZoomView);
744 }; 700 };
745 701
746 // WrenchMenu ------------------------------------------------------------------ 702 // WrenchMenu ------------------------------------------------------------------
747 703
748 WrenchMenu::WrenchMenu(Browser* browser) 704 WrenchMenu::WrenchMenu(Browser* browser)
749 : root_(NULL), 705 : root_(NULL),
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 root_->Cancel(); 942 root_->Cancel();
987 break; 943 break;
988 default: 944 default:
989 NOTREACHED(); 945 NOTREACHED();
990 } 946 }
991 } 947 }
992 948
993 void WrenchMenu::PopulateMenu(MenuItemView* parent, 949 void WrenchMenu::PopulateMenu(MenuItemView* parent,
994 MenuModel* model, 950 MenuModel* model,
995 int* next_id) { 951 int* next_id) {
996 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 952 bool is_new_menu = MenuConfig::IsNewMenu();
997 953
998 int index_offset = model->GetFirstItemIndex(NULL); 954 int index_offset = model->GetFirstItemIndex(NULL);
999 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { 955 for (int i = 0, max = model->GetItemCount(); i < max; ++i) {
1000 int index = i + index_offset; 956 int index = i + index_offset;
1001 957
1002 // The button container menu items have a special height which we have to 958 // The button container menu items have a special height which we have to
1003 // use instead of the normal height. 959 // use instead of the normal height.
1004 int height = 0; 960 int height = 0;
1005 if (is_touch && 961 if (is_new_menu &&
1006 (model->GetCommandIdAt(index) == IDC_CUT || 962 (model->GetCommandIdAt(index) == IDC_CUT ||
1007 model->GetCommandIdAt(index) == IDC_ZOOM_MINUS)) 963 model->GetCommandIdAt(index) == IDC_ZOOM_MINUS))
1008 height = kTouchItemHeight; 964 height = kTouchItemHeight;
sky 2012/08/21 19:36:29 Rename this constant since it isn't just for touch
Mr4D (OOO till 08-26) 2012/08/21 21:34:54 In deed! Done.
1009 965
1010 MenuItemView* item = AppendMenuItem( 966 MenuItemView* item = AppendMenuItem(
1011 parent, model, index, model->GetTypeAt(index), next_id, height); 967 parent, model, index, model->GetTypeAt(index), next_id, height);
1012 968
1013 if (model->GetTypeAt(index) == MenuModel::TYPE_SUBMENU) 969 if (model->GetTypeAt(index) == MenuModel::TYPE_SUBMENU)
1014 PopulateMenu(item, model->GetSubmenuModelAt(index), next_id); 970 PopulateMenu(item, model->GetSubmenuModelAt(index), next_id);
1015 971
1016 switch (model->GetCommandIdAt(index)) { 972 switch (model->GetCommandIdAt(index)) {
1017 case IDC_CUT: 973 case IDC_CUT:
1018 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index)); 974 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 // For menu items with a special menu height we use our special class to be 1024 // For menu items with a special menu height we use our special class to be
1069 // able to modify the item height. 1025 // able to modify the item height.
1070 menu_item = new ButtonContainerMenuItemView(parent, id, height); 1026 menu_item = new ButtonContainerMenuItemView(parent, id, height);
1071 parent->GetSubmenu()->AddChildView(menu_item); 1027 parent->GetSubmenu()->AddChildView(menu_item);
1072 } else { 1028 } else {
1073 // For all other cases we use the more generic way to add menu items. 1029 // For all other cases we use the more generic way to add menu items.
1074 menu_item = parent->AppendMenuItemFromModel(model, index, id); 1030 menu_item = parent->AppendMenuItemFromModel(model, index, id);
1075 } 1031 }
1076 1032
1077 if (menu_item) { 1033 if (menu_item) {
1078 // Flush all buttons to the right side of the menu for touch menus. 1034 bool is_new_menu = views::MenuConfig::IsNewMenu();
1079 menu_item->set_use_right_margin( 1035 // Flush all buttons to the right side of the menu for the new menu type.
1080 ui::GetDisplayLayout() != ui::LAYOUT_TOUCH); 1036 menu_item->set_use_right_margin(!is_new_menu);
1081 menu_item->SetVisible(model->IsVisibleAt(index)); 1037 menu_item->SetVisible(model->IsVisibleAt(index));
1082 1038
1083 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) { 1039 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) {
1084 gfx::ImageSkia icon; 1040 gfx::ImageSkia icon;
1085 if (model->GetIconAt(index, &icon)) 1041 if (model->GetIconAt(index, &icon))
1086 menu_item->SetIcon(icon); 1042 menu_item->SetIcon(icon);
1087 } 1043 }
1088 } 1044 }
1089 1045
1090 return menu_item; 1046 return menu_item;
(...skipping 22 matching lines...) Expand all
1113 bookmark_menu_delegate_.reset( 1069 bookmark_menu_delegate_.reset(
1114 new BookmarkMenuDelegate(browser_, 1070 new BookmarkMenuDelegate(browser_,
1115 browser_, 1071 browser_,
1116 parent, 1072 parent,
1117 first_bookmark_command_id_)); 1073 first_bookmark_command_id_));
1118 bookmark_menu_delegate_->Init( 1074 bookmark_menu_delegate_->Init(
1119 this, bookmark_menu_, model->bookmark_bar_node(), 0, 1075 this, bookmark_menu_, model->bookmark_bar_node(), 0,
1120 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1076 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1121 bookmark_utils::LAUNCH_WRENCH_MENU); 1077 bookmark_utils::LAUNCH_WRENCH_MENU);
1122 } 1078 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698