Commit 90439bdc authored by sadrul@chromium.org's avatar sadrul@chromium.org

views: Fix gesture event propagation in menus.

BUG=136931
TEST=open wrench menu and tap on one of the zoom buttons

Review URL: https://chromiumcodereview.appspot.com/10843060

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149882 0039d316-1c4b-4281-b951-d872f2087c98
parent eed73257
...@@ -93,7 +93,8 @@ class FullscreenButton : public ImageButton { ...@@ -93,7 +93,8 @@ class FullscreenButton : public ImageButton {
explicit FullscreenButton(views::ButtonListener* listener) explicit FullscreenButton(views::ButtonListener* listener)
: ImageButton(listener) { } : ImageButton(listener) { }
virtual gfx::Size GetPreferredSize() { // Overridden from ImageButton.
virtual gfx::Size GetPreferredSize() OVERRIDE {
gfx::Size pref = ImageButton::GetPreferredSize(); gfx::Size pref = ImageButton::GetPreferredSize();
gfx::Insets insets; gfx::Insets insets;
if (border()) if (border())
...@@ -115,11 +116,12 @@ class MenuButtonBorder : public views::Border { ...@@ -115,11 +116,12 @@ class MenuButtonBorder : public views::Border {
kHorizontalTouchPadding : kHorizontalTouchPadding :
kHorizontalPadding) {} kHorizontalPadding) {}
virtual void Paint(const View& view, gfx::Canvas* canvas) const { // Overridden from views::Border.
virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE {
// Painting of border is done in MenuButtonBackground. // Painting of border is done in MenuButtonBackground.
} }
virtual void GetInsets(gfx::Insets* insets) const { virtual void GetInsets(gfx::Insets* insets) const OVERRIDE {
insets->Set(MenuConfig::instance().item_top_margin, insets->Set(MenuConfig::instance().item_top_margin,
horizontal_padding_, horizontal_padding_,
MenuConfig::instance().item_bottom_margin, MenuConfig::instance().item_bottom_margin,
...@@ -162,7 +164,8 @@ class MenuButtonBackground : public views::Background { ...@@ -162,7 +164,8 @@ class MenuButtonBackground : public views::Background {
} }
} }
virtual void Paint(gfx::Canvas* canvas, View* view) const { // Overridden from views::Background.
virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE {
CustomButton::ButtonState state = CustomButton::ButtonState state =
(view->GetClassName() == views::Label::kViewClassName) ? (view->GetClassName() == views::Label::kViewClassName) ?
CustomButton::BS_NORMAL : static_cast<CustomButton*>(view)->state(); CustomButton::BS_NORMAL : static_cast<CustomButton*>(view)->state();
...@@ -294,7 +297,8 @@ class ScheduleAllView : public views::View { ...@@ -294,7 +297,8 @@ class ScheduleAllView : public views::View {
public: public:
ScheduleAllView() {} ScheduleAllView() {}
virtual void SchedulePaintInRect(const gfx::Rect& r) { // Overridden from views::View.
virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE {
View::SchedulePaintInRect(gfx::Rect(0, 0, width(), height())); View::SchedulePaintInRect(gfx::Rect(0, 0, width(), height()));
} }
...@@ -374,14 +378,13 @@ class ButtonContainerMenuItemView : public MenuItemView { ...@@ -374,14 +378,13 @@ class ButtonContainerMenuItemView : public MenuItemView {
public: public:
// Constructor for use with button containing menu items which have a // Constructor for use with button containing menu items which have a
// different height then . // different height then .
explicit ButtonContainerMenuItemView(MenuItemView* parent, ButtonContainerMenuItemView(MenuItemView* parent, int id, int height)
int id,
int height)
: MenuItemView(parent, id, MenuItemView::NORMAL), : MenuItemView(parent, id, MenuItemView::NORMAL),
height_(height) { height_(height) {
}; };
gfx::Size GetChildPreferredSize() OVERRIDE { // Overridden from MenuItemView.
virtual gfx::Size GetChildPreferredSize() OVERRIDE {
gfx::Size size = MenuItemView::GetChildPreferredSize(); gfx::Size size = MenuItemView::GetChildPreferredSize();
// When there is a height override given, we need to deduct our spacing // When there is a height override given, we need to deduct our spacing
// above and below to get to the correct height to return here for the // above and below to get to the correct height to return here for the
...@@ -409,7 +412,8 @@ class TintedImageSource: public gfx::CanvasImageSource { ...@@ -409,7 +412,8 @@ class TintedImageSource: public gfx::CanvasImageSource {
virtual ~TintedImageSource() { virtual ~TintedImageSource() {
} }
void Draw(gfx::Canvas* canvas) OVERRIDE { // Overridden from gfx::CanvasImageSource.
virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
canvas->DrawImageInt(image_, 0, 0); canvas->DrawImageInt(image_, 0, 0);
SkPaint paint; SkPaint paint;
// We leave the old alpha alone and add the new color multiplied // We leave the old alpha alone and add the new color multiplied
...@@ -466,21 +470,23 @@ class WrenchMenu::CutCopyPasteView : public WrenchMenuView { ...@@ -466,21 +470,23 @@ class WrenchMenu::CutCopyPasteView : public WrenchMenuView {
copy_background->SetOtherButtons(cut, paste); copy_background->SetOtherButtons(cut, paste);
} }
gfx::Size GetPreferredSize() { // Overridden from View.
virtual gfx::Size GetPreferredSize() OVERRIDE {
// Returned height doesn't matter as MenuItemView forces everything to the // Returned height doesn't matter as MenuItemView forces everything to the
// height of the menuitemview. // height of the menuitemview.
return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0);
} }
void Layout() { virtual void Layout() OVERRIDE {
// All buttons are given the same width. // All buttons are given the same width.
int width = GetMaxChildViewPreferredWidth(); int width = GetMaxChildViewPreferredWidth();
for (int i = 0; i < child_count(); ++i) for (int i = 0; i < child_count(); ++i)
child_at(i)->SetBounds(i * width, 0, width, height()); child_at(i)->SetBounds(i * width, 0, width, height());
} }
// ButtonListener // Overridden from ButtonListener.
virtual void ButtonPressed(views::Button* sender, const views::Event& event) { virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE {
menu_->CancelAndEvaluate(menu_model_, sender->tag()); menu_->CancelAndEvaluate(menu_model_, sender->tag());
} }
...@@ -596,7 +602,8 @@ class WrenchMenu::ZoomView : public WrenchMenuView, ...@@ -596,7 +602,8 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); HostZoomMap::GetForBrowserContext(menu->browser_->profile())));
} }
gfx::Size GetPreferredSize() { // Overridden from View.
virtual gfx::Size GetPreferredSize() OVERRIDE {
// The increment/decrement button are forced to the same width. // The increment/decrement button are forced to the same width.
int button_width = std::max(increment_button_->GetPreferredSize().width(), int button_width = std::max(increment_button_->GetPreferredSize().width(),
decrement_button_->GetPreferredSize().width()); decrement_button_->GetPreferredSize().width());
...@@ -611,7 +618,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView, ...@@ -611,7 +618,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
fullscreen_width, 0); fullscreen_width, 0);
} }
void Layout() { virtual void Layout() OVERRIDE {
int x = 0; int x = 0;
int button_width = std::max(increment_button_->GetPreferredSize().width(), int button_width = std::max(increment_button_->GetPreferredSize().width(),
decrement_button_->GetPreferredSize().width()); decrement_button_->GetPreferredSize().width());
...@@ -637,8 +644,9 @@ class WrenchMenu::ZoomView : public WrenchMenuView, ...@@ -637,8 +644,9 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
fullscreen_button_->SetBoundsRect(bounds); fullscreen_button_->SetBoundsRect(bounds);
} }
// ButtonListener: // Overridden from ButtonListener.
virtual void ButtonPressed(views::Button* sender, const views::Event& event) { virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE {
if (sender->tag() == fullscreen_index_) { if (sender->tag() == fullscreen_index_) {
menu_->CancelAndEvaluate(menu_model_, sender->tag()); menu_->CancelAndEvaluate(menu_model_, sender->tag());
} else { } else {
...@@ -647,10 +655,10 @@ class WrenchMenu::ZoomView : public WrenchMenuView, ...@@ -647,10 +655,10 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
} }
} }
// content::NotificationObserver: // Overridden from content::NotificationObserver.
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) OVERRIDE {
DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type);
UpdateZoomControls(); UpdateZoomControls();
} }
......
...@@ -63,6 +63,7 @@ bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) { ...@@ -63,6 +63,7 @@ bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) {
} }
ui::GestureStatus MenuHostRootView::OnGestureEvent(const GestureEvent& event) { ui::GestureStatus MenuHostRootView::OnGestureEvent(const GestureEvent& event) {
RootView::OnGestureEvent(event);
// ChromeOS uses MenuController to forward events like other // ChromeOS uses MenuController to forward events like other
// mouse events. // mouse events.
if (!GetMenuController()) if (!GetMenuController())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment