[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / views / controls / menu / menu_host_root_view.cc
bloba46b81b8327e1e10a37ab657eaa8eddefb515e24
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 ui::EventDispatchDetails MenuHostRootView::OnEventFromSource(ui::Event* event) {
59 ui::EventDispatchDetails result = RootView::OnEventFromSource(event);
61 if (event->IsGestureEvent()) {
62 ui::GestureEvent* gesture_event = event->AsGestureEvent();
63 if (gesture_event->handled())
64 return result;
65 // ChromeOS uses MenuController to forward events like other
66 // mouse events.
67 if (!GetMenuController())
68 return result;
69 GetMenuController()->OnGestureEvent(submenu_, gesture_event);
72 return result;
75 MenuController* MenuHostRootView::GetMenuController() {
76 return submenu_ ? submenu_->GetMenuItem()->GetMenuController() : NULL;
79 bool MenuHostRootView::DoesEventTargetEmptyMenuItem(
80 const ui::MouseEvent& event) {
81 View* view = GetEventHandlerForPoint(event.location());
82 return view && view->id() == MenuItemView::kEmptyMenuItemViewID;
85 } // namespace views