blob: e1c119f96bf0254ed4e8a46a2ffedc257a75d20f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "views/controls/menu/menu_host_root_view.h"
#include "views/controls/menu/menu_controller.h"
#include "views/controls/menu/submenu_view.h"
namespace views {
MenuHostRootView::MenuHostRootView(Widget* widget,
SubmenuView* submenu)
: RootView(widget),
submenu_(submenu),
forward_drag_to_menu_controller_(true) {
}
bool MenuHostRootView::OnMousePressed(const MouseEvent& event) {
forward_drag_to_menu_controller_ =
!GetLocalBounds().Contains(event.location()) ||
!RootView::OnMousePressed(event);
if (forward_drag_to_menu_controller_ && GetMenuController())
GetMenuController()->OnMousePressed(submenu_, event);
return true;
}
bool MenuHostRootView::OnMouseDragged(const MouseEvent& event) {
if (forward_drag_to_menu_controller_ && GetMenuController()) {
GetMenuController()->OnMouseDragged(submenu_, event);
return true;
}
return RootView::OnMouseDragged(event);
}
void MenuHostRootView::OnMouseReleased(const MouseEvent& event) {
RootView::OnMouseReleased(event);
if (forward_drag_to_menu_controller_ && GetMenuController()) {
forward_drag_to_menu_controller_ = false;
GetMenuController()->OnMouseReleased(submenu_, event);
}
}
void MenuHostRootView::OnMouseMoved(const MouseEvent& event) {
RootView::OnMouseMoved(event);
if (GetMenuController())
GetMenuController()->OnMouseMoved(submenu_, event);
}
bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) {
#if defined(OS_LINUX)
// ChromeOS uses MenuController to forward events like other
// mouse events.
return GetMenuController() &&
GetMenuController()->OnMouseWheel(submenu_, event);
#else
// Windows uses focus_util_win::RerouteMouseWheel to forward events to
// the right menu.
// RootView::OnMouseWheel forwards to the focused view. We don't have a
// focused view, so we need to override this then forward to the menu.
return submenu_->OnMouseWheel(event);
#endif
}
MenuController* MenuHostRootView::GetMenuController() {
return submenu_ ? submenu_->GetMenuItem()->GetMenuController() : NULL;
}
} // namespace views
|