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

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: And another merge! 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
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_win.cc ('k') | ui/base/models/menu_model.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const SkColor kBorderColor = SkColorSetARGB(36, 0, 0, 0); 71 const SkColor kBorderColor = SkColorSetARGB(36, 0, 0, 0);
72 const SkColor kPushedBorderColor = SkColorSetARGB(72, 0, 0, 0); 72 const SkColor kPushedBorderColor = SkColorSetARGB(72, 0, 0, 0);
73 const SkColor kHotBackgroundColor = SkColorSetARGB(204, 255, 255, 255); 73 const SkColor kHotBackgroundColor = SkColorSetARGB(204, 255, 255, 255);
74 const SkColor kBackgroundColor = SkColorSetARGB(102, 255, 255, 255); 74 const SkColor kBackgroundColor = SkColorSetARGB(102, 255, 255, 255);
75 const SkColor kPushedBackgroundColor = SkColorSetARGB(13, 0, 0, 0); 75 const SkColor kPushedBackgroundColor = SkColorSetARGB(13, 0, 0, 0);
76 const SkColor kTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); 76 const SkColor kTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255);
77 const SkColor kHotTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); 77 const SkColor kHotTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242);
78 const SkColor kPushedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); 78 const SkColor kPushedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235);
79 79
80 const SkColor kTouchButtonText = 0xff5a5a5a; 80 const SkColor kTouchButtonText = 0xff5a5a5a;
81 const SkColor kTouchImageBrighten = 0x80ffffff;
82 81
83 // Horizontal padding on the edges of the buttons. 82 // Horizontal padding on the edges of the buttons.
84 const int kHorizontalPadding = 6; 83 const int kHorizontalPadding = 6;
85 // Horizontal padding for a touch enabled menu. 84 // Horizontal padding for a touch enabled menu.
86 const int kHorizontalTouchPadding = 15; 85 const int kHorizontalTouchPadding = 15;
87 86
88 // For touch menu items we want to have this height in pixels. 87 // Menu items which have embedded buttons should have this height in pixel.
89 const int kTouchItemHeight = 47; 88 const int kMenuItemContainingButtonsHeight = 43;
89
90 // Returns true when the new menu style is used.
91 // TODO(skuhne): Remove when only the new menu style is left.
92 bool IsNewMenu() {
93 #if defined(USE_AURA)
94 return true;
95 #else
96 return ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
97 #endif
98 }
90 99
91 // Subclass of ImageButton whose preferred size includes the size of the border. 100 // Subclass of ImageButton whose preferred size includes the size of the border.
92 class FullscreenButton : public ImageButton { 101 class FullscreenButton : public ImageButton {
93 public: 102 public:
94 explicit FullscreenButton(views::ButtonListener* listener) 103 explicit FullscreenButton(views::ButtonListener* listener)
95 : ImageButton(listener) { } 104 : ImageButton(listener) { }
96 105
97 // Overridden from ImageButton. 106 // Overridden from ImageButton.
98 virtual gfx::Size GetPreferredSize() OVERRIDE { 107 virtual gfx::Size GetPreferredSize() OVERRIDE {
99 gfx::Size pref = ImageButton::GetPreferredSize(); 108 gfx::Size pref = ImageButton::GetPreferredSize();
100 gfx::Insets insets; 109 gfx::Insets insets;
101 if (border()) 110 if (border())
102 border()->GetInsets(&insets); 111 border()->GetInsets(&insets);
103 pref.Enlarge(insets.width(), insets.height()); 112 pref.Enlarge(insets.width(), insets.height());
104 return pref; 113 return pref;
105 } 114 }
106 115
107 private: 116 private:
108 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); 117 DISALLOW_COPY_AND_ASSIGN(FullscreenButton);
109 }; 118 };
110 119
111 // Border for buttons contained in the menu. This is only used for getting the 120 // Border for buttons contained in the menu. This is only used for getting the
112 // insets, the actual painting is done in MenuButtonBackground. 121 // insets, the actual painting is done in MenuButtonBackground.
113 class MenuButtonBorder : public views::Border { 122 class MenuButtonBorder : public views::Border {
114 public: 123 public:
115 MenuButtonBorder() 124 MenuButtonBorder()
116 : horizontal_padding_(ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? 125 : horizontal_padding_(IsNewMenu() ?
117 kHorizontalTouchPadding : 126 kHorizontalTouchPadding :
118 kHorizontalPadding) {} 127 kHorizontalPadding) {}
119 128
120 // Overridden from views::Border. 129 // Overridden from views::Border.
121 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE { 130 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE {
122 // Painting of border is done in MenuButtonBackground. 131 // Painting of border is done in MenuButtonBackground.
123 } 132 }
124 133
125 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE { 134 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE {
126 insets->Set(MenuConfig::instance().item_top_margin, 135 insets->Set(MenuConfig::instance().item_top_margin,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Overridden from views::Background. 177 // Overridden from views::Background.
169 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { 178 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE {
170 CustomButton::ButtonState state = 179 CustomButton::ButtonState state =
171 (view->GetClassName() == views::Label::kViewClassName) ? 180 (view->GetClassName() == views::Label::kViewClassName) ?
172 CustomButton::BS_NORMAL : static_cast<CustomButton*>(view)->state(); 181 CustomButton::BS_NORMAL : static_cast<CustomButton*>(view)->state();
173 int w = view->width(); 182 int w = view->width();
174 int h = view->height(); 183 int h = view->height();
175 // Windows is drawing its own separators and we cannot use the touch button 184 // Windows is drawing its own separators and we cannot use the touch button
176 // for that. 185 // for that.
177 #if !defined(OS_WIN) 186 #if !defined(OS_WIN)
178 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { 187 if (IsNewMenu()) {
179 // Normal buttons get a border drawn on the right side and the rest gets 188 // Normal buttons get a border drawn on the right side and the rest gets
180 // filled in. The left button however does not get a line to combine 189 // filled in. The left button however does not get a line to combine
181 // buttons. 190 // buttons.
182 int border = 0; 191 int border = 0;
183 if (type_ != RIGHT_BUTTON) { 192 if (type_ != RIGHT_BUTTON) {
184 border = 1; 193 border = 1;
185 canvas->FillRect(gfx::Rect(0, 0, border, h), 194 canvas->FillRect(gfx::Rect(0, 0, border, h),
186 border_color(CustomButton::BS_NORMAL)); 195 border_color(CustomButton::BS_NORMAL));
187 } 196 }
188 canvas->FillRect(gfx::Rect(border, 0, w - border, h), 197 canvas->FillRect(gfx::Rect(border, 0, w - border, h),
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 size.set_height(height); 404 size.set_height(height);
396 return size; 405 return size;
397 } 406 }
398 407
399 private: 408 private:
400 int height_; 409 int height_;
401 410
402 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); 411 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView);
403 }; 412 };
404 413
405 class TintedImageSource: public gfx::CanvasImageSource {
406 public:
407 TintedImageSource(gfx::ImageSkia& image, SkColor tint_value)
408 : CanvasImageSource(image.size(), false),
409 image_(image),
410 tint_value_(tint_value) {
411 }
412
413 virtual ~TintedImageSource() {
414 }
415
416 // Overridden from gfx::CanvasImageSource.
417 virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
418 canvas->DrawImageInt(image_, 0, 0);
419 SkPaint paint;
420 // We leave the old alpha alone and add the new color multiplied
421 // with the source alpha to the existing alpha. Thus: We brighten
422 // the image up - but only the non transparent pixels.
423 paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
424 paint.setColor(tint_value_);
425 canvas->sk_canvas()->drawPaint(paint);
426 }
427
428 private:
429 const gfx::ImageSkia image_;
430 const SkColor tint_value_;
431
432 DISALLOW_COPY_AND_ASSIGN(TintedImageSource);
433 };
434
435 } // namespace 414 } // namespace
436 415
437 // CutCopyPasteView ------------------------------------------------------------ 416 // CutCopyPasteView ------------------------------------------------------------
438 417
439 // CutCopyPasteView is the view containing the cut/copy/paste buttons. 418 // CutCopyPasteView is the view containing the cut/copy/paste buttons.
440 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { 419 class WrenchMenu::CutCopyPasteView : public WrenchMenuView {
441 public: 420 public:
442 CutCopyPasteView(WrenchMenu* menu, 421 CutCopyPasteView(WrenchMenu* menu,
443 MenuModel* menu_model, 422 MenuModel* menu_model,
444 int cut_index, 423 int cut_index,
445 int copy_index, 424 int copy_index,
446 int paste_index) 425 int paste_index)
447 : WrenchMenuView(menu, menu_model) { 426 : WrenchMenuView(menu, menu_model) {
448 TextButton* cut = CreateAndConfigureButton( 427 TextButton* cut = CreateAndConfigureButton(
449 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); 428 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL);
450 429
451 MenuButtonBackground* copy_background = NULL; 430 MenuButtonBackground* copy_background = NULL;
452 TextButton* copy = CreateAndConfigureButton( 431 TextButton* copy = CreateAndConfigureButton(
453 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, 432 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index,
454 &copy_background); 433 &copy_background);
455 434
456 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 435 bool is_new_menu = IsNewMenu();
457 436
458 TextButton* paste = CreateAndConfigureButton( 437 TextButton* paste = CreateAndConfigureButton(
459 IDS_PASTE, 438 IDS_PASTE,
460 #if !defined(OS_WIN) 439 #if !defined(OS_WIN)
461 is_touch ? MenuButtonBackground::CENTER_BUTTON : 440 is_new_menu ? MenuButtonBackground::CENTER_BUTTON :
462 #endif 441 #endif
463 MenuButtonBackground::RIGHT_BUTTON, 442 MenuButtonBackground::RIGHT_BUTTON,
464 paste_index, 443 paste_index,
465 NULL); 444 NULL);
466 if (is_touch) { 445 if (is_new_menu) {
467 cut->SetEnabledColor(kTouchButtonText); 446 cut->SetEnabledColor(kTouchButtonText);
468 copy->SetEnabledColor(kTouchButtonText); 447 copy->SetEnabledColor(kTouchButtonText);
469 paste->SetEnabledColor(kTouchButtonText); 448 paste->SetEnabledColor(kTouchButtonText);
470 } 449 }
471 copy_background->SetOtherButtons(cut, paste); 450 copy_background->SetOtherButtons(cut, paste);
472 } 451 }
473 452
474 // Overridden from View. 453 // Overridden from View.
475 virtual gfx::Size GetPreferredSize() OVERRIDE { 454 virtual gfx::Size GetPreferredSize() OVERRIDE {
476 // Returned height doesn't matter as MenuItemView forces everything to the 455 // Returned height doesn't matter as MenuItemView forces everything to the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 zoom_label_width_(0) { 508 zoom_label_width_(0) {
530 decrement_button_ = CreateButtonWithAccName( 509 decrement_button_ = CreateButtonWithAccName(
531 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, 510 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index,
532 NULL, IDS_ACCNAME_ZOOM_MINUS2); 511 NULL, IDS_ACCNAME_ZOOM_MINUS2);
533 512
534 zoom_label_ = new Label( 513 zoom_label_ = new Label(
535 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 514 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
536 zoom_label_->SetAutoColorReadabilityEnabled(false); 515 zoom_label_->SetAutoColorReadabilityEnabled(false);
537 zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT); 516 zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT);
538 517
539 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 518 bool is_new_menu = IsNewMenu();
540 519
541 MenuButtonBackground* center_bg = new MenuButtonBackground( 520 MenuButtonBackground* center_bg = new MenuButtonBackground(
542 #if !defined(OS_WIN) 521 #if !defined(OS_WIN)
543 is_touch ? MenuButtonBackground::RIGHT_BUTTON : 522 is_new_menu ? MenuButtonBackground::RIGHT_BUTTON :
544 #endif 523 #endif
545 MenuButtonBackground::CENTER_BUTTON); 524 MenuButtonBackground::CENTER_BUTTON);
546 zoom_label_->set_background(center_bg); 525 zoom_label_->set_background(center_bg);
547 zoom_label_->set_border(new MenuButtonBorder()); 526 zoom_label_->set_border(new MenuButtonBorder());
548 zoom_label_->SetFont(MenuConfig::instance().font); 527 zoom_label_->SetFont(MenuConfig::instance().font);
549 528
550 AddChildView(zoom_label_); 529 AddChildView(zoom_label_);
551 zoom_label_width_ = MaxWidthForZoomLabel(); 530 zoom_label_width_ = MaxWidthForZoomLabel();
552 531
553 increment_button_ = CreateButtonWithAccName( 532 increment_button_ = CreateButtonWithAccName(
554 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, 533 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index,
555 NULL, IDS_ACCNAME_ZOOM_PLUS2); 534 NULL, IDS_ACCNAME_ZOOM_PLUS2);
556 535
557 center_bg->SetOtherButtons(decrement_button_, increment_button_); 536 center_bg->SetOtherButtons(decrement_button_, increment_button_);
558 537
559 fullscreen_button_ = new FullscreenButton(this); 538 fullscreen_button_ = new FullscreenButton(this);
560 gfx::ImageSkia* full_screen_image = 539 gfx::ImageSkia* full_screen_image =
561 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 540 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
562 IDR_FULLSCREEN_MENU_BUTTON); 541 IDR_FULLSCREEN_MENU_BUTTON);
563 if (is_touch) { 542 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image);
564 // In case of touch, the menu needs to be brightened up a bit. 543 if (is_new_menu) {
565 gfx::CanvasImageSource* source = new TintedImageSource(
566 *full_screen_image, kTouchImageBrighten);
567 // ImageSkia takes ownership of |source|.
568 tinted_fullscreen_image_ = gfx::ImageSkia(source, source->size());
569 fullscreen_button_->SetImage(ImageButton::BS_NORMAL,
570 &tinted_fullscreen_image_);
571 } else {
572 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image);
573 }
574 if (is_touch) {
575 zoom_label_->SetEnabledColor(kTouchButtonText); 544 zoom_label_->SetEnabledColor(kTouchButtonText);
576 decrement_button_->SetEnabledColor(kTouchButtonText); 545 decrement_button_->SetEnabledColor(kTouchButtonText);
577 increment_button_->SetEnabledColor(kTouchButtonText); 546 increment_button_->SetEnabledColor(kTouchButtonText);
578 } else { 547 } else {
579 zoom_label_->SetEnabledColor(MenuConfig::instance().text_color); 548 zoom_label_->SetEnabledColor(MenuConfig::instance().text_color);
580 } 549 }
581 550
582 fullscreen_button_->set_focusable(true); 551 fullscreen_button_->set_focusable(true);
583 fullscreen_button_->set_request_focus_on_press(false); 552 fullscreen_button_->set_request_focus_on_press(false);
584 fullscreen_button_->set_tag(fullscreen_index); 553 fullscreen_button_->set_tag(fullscreen_index);
585 fullscreen_button_->SetImageAlignment( 554 fullscreen_button_->SetImageAlignment(
586 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); 555 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
587 int horizontal_padding = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? 556 int horizontal_padding = IsNewMenu() ?
588 kHorizontalTouchPadding : kHorizontalPadding; 557 kHorizontalTouchPadding : kHorizontalPadding;
589 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( 558 fullscreen_button_->set_border(views::Border::CreateEmptyBorder(
590 0, horizontal_padding, 0, horizontal_padding)); 559 0, horizontal_padding, 0, horizontal_padding));
591 fullscreen_button_->set_background( 560 fullscreen_button_->set_background(
592 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON)); 561 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON));
593 fullscreen_button_->SetAccessibleName( 562 fullscreen_button_->SetAccessibleName(
594 GetAccessibleNameForWrenchMenuItem( 563 GetAccessibleNameForWrenchMenuItem(
595 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); 564 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
596 AddChildView(fullscreen_button_); 565 AddChildView(fullscreen_button_);
597 566
598 UpdateZoomControls(); 567 UpdateZoomControls();
599 568
600 registrar_.Add( 569 registrar_.Add(
601 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 570 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
602 content::Source<HostZoomMap>( 571 content::Source<HostZoomMap>(
603 HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); 572 HostZoomMap::GetForBrowserContext(menu->browser_->profile())));
604 } 573 }
605 574
606 // Overridden from View. 575 // Overridden from View.
607 virtual gfx::Size GetPreferredSize() OVERRIDE { 576 virtual gfx::Size GetPreferredSize() OVERRIDE {
608 // The increment/decrement button are forced to the same width. 577 // The increment/decrement button are forced to the same width.
609 int button_width = std::max(increment_button_->GetPreferredSize().width(), 578 int button_width = std::max(increment_button_->GetPreferredSize().width(),
610 decrement_button_->GetPreferredSize().width()); 579 decrement_button_->GetPreferredSize().width());
611 int zoom_padding = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? 580 int zoom_padding = IsNewMenu() ? kTouchZoomPadding : kZoomPadding;
612 kTouchZoomPadding : kZoomPadding;
613 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + 581 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() +
614 zoom_padding; 582 zoom_padding;
615 // Returned height doesn't matter as MenuItemView forces everything to the 583 // Returned height doesn't matter as MenuItemView forces everything to the
616 // height of the menuitemview. Note that we have overridden the height when 584 // height of the menuitemview. Note that we have overridden the height when
617 // constructing the menu. 585 // constructing the menu.
618 return gfx::Size(button_width + zoom_label_width_ + button_width + 586 return gfx::Size(button_width + zoom_label_width_ + button_width +
619 fullscreen_width, 0); 587 fullscreen_width, 0);
620 } 588 }
621 589
622 virtual void Layout() OVERRIDE { 590 virtual void Layout() OVERRIDE {
623 int x = 0; 591 int x = 0;
624 int button_width = std::max(increment_button_->GetPreferredSize().width(), 592 int button_width = std::max(increment_button_->GetPreferredSize().width(),
625 decrement_button_->GetPreferredSize().width()); 593 decrement_button_->GetPreferredSize().width());
626 gfx::Rect bounds(0, 0, button_width, height()); 594 gfx::Rect bounds(0, 0, button_width, height());
627 595
628 decrement_button_->SetBoundsRect(bounds); 596 decrement_button_->SetBoundsRect(bounds);
629 597
630 x += bounds.width(); 598 x += bounds.width();
631 bounds.set_x(x); 599 bounds.set_x(x);
632 bounds.set_width(zoom_label_width_); 600 bounds.set_width(zoom_label_width_);
633 zoom_label_->SetBoundsRect(bounds); 601 zoom_label_->SetBoundsRect(bounds);
634 602
635 x += bounds.width(); 603 x += bounds.width();
636 bounds.set_x(x); 604 bounds.set_x(x);
637 bounds.set_width(button_width); 605 bounds.set_width(button_width);
638 increment_button_->SetBoundsRect(bounds); 606 increment_button_->SetBoundsRect(bounds);
639 607
640 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 608 bool is_new_menu = IsNewMenu();
641 x += bounds.width() + (is_touch ? 0 : kZoomPadding); 609 x += bounds.width() + (is_new_menu ? 0 : kZoomPadding);
642 bounds.set_x(x); 610 bounds.set_x(x);
643 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + 611 bounds.set_width(fullscreen_button_->GetPreferredSize().width() +
644 (is_touch ? kTouchZoomPadding : 0)); 612 (is_new_menu ? kTouchZoomPadding : 0));
645 fullscreen_button_->SetBoundsRect(bounds); 613 fullscreen_button_->SetBoundsRect(bounds);
646 } 614 }
647 615
648 // Overridden from ButtonListener. 616 // Overridden from ButtonListener.
649 virtual void ButtonPressed(views::Button* sender, 617 virtual void ButtonPressed(views::Button* sender,
650 const ui::Event& event) OVERRIDE { 618 const ui::Event& event) OVERRIDE {
651 if (sender->tag() == fullscreen_index_) { 619 if (sender->tag() == fullscreen_index_) {
652 menu_->CancelAndEvaluate(menu_model_, sender->tag()); 620 menu_->CancelAndEvaluate(menu_model_, sender->tag());
653 } else { 621 } else {
654 // Zoom buttons don't close the menu. 622 // Zoom buttons don't close the menu.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 TextButton* increment_button_; 696 TextButton* increment_button_;
729 697
730 // Label showing zoom as a percent. 698 // Label showing zoom as a percent.
731 Label* zoom_label_; 699 Label* zoom_label_;
732 700
733 // Button for decrementing the zoom. 701 // Button for decrementing the zoom.
734 TextButton* decrement_button_; 702 TextButton* decrement_button_;
735 703
736 ImageButton* fullscreen_button_; 704 ImageButton* fullscreen_button_;
737 705
738 // The tinted bitmap of the fullscreen button.
739 gfx::ImageSkia tinted_fullscreen_image_;
740
741 // Width given to |zoom_label_|. This is the width at 100%. 706 // Width given to |zoom_label_|. This is the width at 100%.
742 int zoom_label_width_; 707 int zoom_label_width_;
743 708
744 DISALLOW_COPY_AND_ASSIGN(ZoomView); 709 DISALLOW_COPY_AND_ASSIGN(ZoomView);
745 }; 710 };
746 711
747 // WrenchMenu ------------------------------------------------------------------ 712 // WrenchMenu ------------------------------------------------------------------
748 713
749 WrenchMenu::WrenchMenu(Browser* browser) 714 WrenchMenu::WrenchMenu(Browser* browser)
750 : root_(NULL), 715 : root_(NULL),
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 root_->Cancel(); 956 root_->Cancel();
992 break; 957 break;
993 default: 958 default:
994 NOTREACHED(); 959 NOTREACHED();
995 } 960 }
996 } 961 }
997 962
998 void WrenchMenu::PopulateMenu(MenuItemView* parent, 963 void WrenchMenu::PopulateMenu(MenuItemView* parent,
999 MenuModel* model, 964 MenuModel* model,
1000 int* next_id) { 965 int* next_id) {
1001 bool is_touch = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; 966 bool is_new_menu = IsNewMenu();
1002 967
1003 int index_offset = model->GetFirstItemIndex(NULL); 968 int index_offset = model->GetFirstItemIndex(NULL);
1004 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { 969 for (int i = 0, max = model->GetItemCount(); i < max; ++i) {
1005 int index = i + index_offset; 970 int index = i + index_offset;
1006 971
1007 // The button container menu items have a special height which we have to 972 // The button container menu items have a special height which we have to
1008 // use instead of the normal height. 973 // use instead of the normal height.
1009 int height = 0; 974 int height = 0;
1010 if (is_touch && 975 if (is_new_menu &&
1011 (model->GetCommandIdAt(index) == IDC_CUT || 976 (model->GetCommandIdAt(index) == IDC_CUT ||
1012 model->GetCommandIdAt(index) == IDC_ZOOM_MINUS)) 977 model->GetCommandIdAt(index) == IDC_ZOOM_MINUS))
1013 height = kTouchItemHeight; 978 height = kMenuItemContainingButtonsHeight;
1014 979
1015 MenuItemView* item = AppendMenuItem( 980 MenuItemView* item = AppendMenuItem(
1016 parent, model, index, model->GetTypeAt(index), next_id, height); 981 parent, model, index, model->GetTypeAt(index), next_id, height);
1017 982
1018 if (model->GetTypeAt(index) == MenuModel::TYPE_SUBMENU) 983 if (model->GetTypeAt(index) == MenuModel::TYPE_SUBMENU)
1019 PopulateMenu(item, model->GetSubmenuModelAt(index), next_id); 984 PopulateMenu(item, model->GetSubmenuModelAt(index), next_id);
1020 985
1021 switch (model->GetCommandIdAt(index)) { 986 switch (model->GetCommandIdAt(index)) {
1022 case IDC_CUT: 987 case IDC_CUT:
1023 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index)); 988 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 // For menu items with a special menu height we use our special class to be 1038 // For menu items with a special menu height we use our special class to be
1074 // able to modify the item height. 1039 // able to modify the item height.
1075 menu_item = new ButtonContainerMenuItemView(parent, id, height); 1040 menu_item = new ButtonContainerMenuItemView(parent, id, height);
1076 parent->GetSubmenu()->AddChildView(menu_item); 1041 parent->GetSubmenu()->AddChildView(menu_item);
1077 } else { 1042 } else {
1078 // For all other cases we use the more generic way to add menu items. 1043 // For all other cases we use the more generic way to add menu items.
1079 menu_item = parent->AppendMenuItemFromModel(model, index, id); 1044 menu_item = parent->AppendMenuItemFromModel(model, index, id);
1080 } 1045 }
1081 1046
1082 if (menu_item) { 1047 if (menu_item) {
1083 // Flush all buttons to the right side of the menu for touch menus. 1048 bool is_new_menu = IsNewMenu();
1084 menu_item->set_use_right_margin( 1049 // Flush all buttons to the right side of the menu for the new menu type.
1085 ui::GetDisplayLayout() != ui::LAYOUT_TOUCH); 1050 menu_item->set_use_right_margin(!is_new_menu);
1086 menu_item->SetVisible(model->IsVisibleAt(index)); 1051 menu_item->SetVisible(model->IsVisibleAt(index));
1087 1052
1088 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) { 1053 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) {
1089 gfx::Image icon; 1054 gfx::Image icon;
1090 if (model->GetIconAt(index, &icon)) 1055 if (model->GetIconAt(index, &icon))
1091 menu_item->SetIcon(*icon.ToImageSkia()); 1056 menu_item->SetIcon(*icon.ToImageSkia());
1092 } 1057 }
1093 } 1058 }
1094 1059
1095 return menu_item; 1060 return menu_item;
(...skipping 22 matching lines...) Expand all
1118 bookmark_menu_delegate_.reset( 1083 bookmark_menu_delegate_.reset(
1119 new BookmarkMenuDelegate(browser_, 1084 new BookmarkMenuDelegate(browser_,
1120 browser_, 1085 browser_,
1121 parent, 1086 parent,
1122 first_bookmark_command_id_)); 1087 first_bookmark_command_id_));
1123 bookmark_menu_delegate_->Init( 1088 bookmark_menu_delegate_->Init(
1124 this, bookmark_menu_, model->bookmark_bar_node(), 0, 1089 this, bookmark_menu_, model->bookmark_bar_node(), 0,
1125 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1090 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1126 bookmark_utils::LAUNCH_WRENCH_MENU); 1091 bookmark_utils::LAUNCH_WRENCH_MENU);
1127 } 1092 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_win.cc ('k') | ui/base/models/menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698