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

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

Powered by Google App Engine
This is Rietveld 408576698