Add ICU message format support
[chromium-blink-merge.git] / ui / views / controls / menu / menu_host_root_view.cc
blob1bc834a0098e5edb1a1fa41a163dd06712bfe7a6
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
3 // found in the LICENSE file.
5 #include "ui/views/controls/menu/menu_host_root_view.h"
7 #include "ui/views/controls/menu/menu_controller.h"
8 #include "ui/views/controls/menu/menu_item_view.h"
9 #include "ui/views/controls/menu/submenu_view.h"
11 namespace views {
13 MenuHostRootView::MenuHostRootView(Widget* widget,
14 SubmenuView* submenu)
15 : internal::RootView(widget),
16 submenu_(submenu),
17 forward_drag_to_menu_controller_(true) {
20 bool MenuHostRootView::OnMousePressed(const ui::MouseEvent& event) {
21 forward_drag_to_menu_controller_ =
22 !GetLocalBounds().Contains(event.location()) ||
23 !RootView::OnMousePressed(event) ||
24 DoesEventTargetEmptyMenuItem(event);
26 if (forward_drag_to_menu_controller_ && GetMenuController())
27 GetMenuController()->OnMousePressed(submenu_, event);
28 return true;
31 bool MenuHostRootView::OnMouseDragged(const ui::MouseEvent& event) {
32 if (forward_drag_to_menu_controller_ && GetMenuController()) {
33 GetMenuController()->OnMouseDragged(submenu_, event);
34 return true;
36 return RootView::OnMouseDragged(event);
39 void MenuHostRootView::OnMouseReleased(const ui::MouseEvent& event) {
40 RootView::OnMouseReleased(event);
41 if (forward_drag_to_menu_controller_ && GetMenuController()) {
42 forward_drag_to_menu_controller_ = false;
43 GetMenuController()->OnMouseReleased(submenu_, event);
47 void MenuHostRootView::OnMouseMoved(const ui::MouseEvent& event) {
48 RootView::OnMouseMoved(event);
49 if (GetMenuController())
50 GetMenuController()->OnMouseMoved(submenu_, event);
53 bool MenuHostRootView::OnMouseWheel(const ui::MouseWheelEvent& event) {
54 return GetMenuController() &&
55 GetMenuController()->OnMouseWheel(submenu_, event);
58 void MenuHostRootView::OnEventProcessingFinished(ui::Event* event) {
59 RootView::OnEventProcessingFinished(event);
61 // Forward unhandled gesture events to our menu controller.
62 // TODO(tdanderson): Investigate whether this should be moved into a
63 // post-target handler installed on |this| instead
64 // (invoked only if event->target() == this).
65 if (event->IsGestureEvent() && !event->handled() && GetMenuController())
66 GetMenuController()->OnGestureEvent(submenu_, event->AsGestureEvent());
69 MenuController* MenuHostRootView::GetMenuController() {
70 return submenu_ ? submenu_->GetMenuItem()->GetMenuController() : NULL;
73 bool MenuHostRootView::DoesEventTargetEmptyMenuItem(
74 const ui::MouseEvent& event) {
75 View* view = GetEventHandlerForPoint(event.location());
76 return view && view->id() == MenuItemView::kEmptyMenuItemViewID;
79 } // namespace views