blob: cc0124c311c9c34fc5674a003a4ca0835d75f981 (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// 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),
suspend_events_(false) {
}
bool MenuHostRootView::OnMousePressed(const MouseEvent& event) {
if (suspend_events_)
return true;
forward_drag_to_menu_controller_ =
((event.x() < 0 || event.y() < 0 || event.x() >= width() ||
event.y() >= height()) ||
!RootView::OnMousePressed(event));
if (forward_drag_to_menu_controller_ && GetMenuController())
GetMenuController()->OnMousePressed(submenu_, event);
return true;
}
bool MenuHostRootView::OnMouseDragged(const MouseEvent& event) {
if (suspend_events_)
return true;
if (forward_drag_to_menu_controller_ && GetMenuController()) {
GetMenuController()->OnMouseDragged(submenu_, event);
return true;
}
return RootView::OnMouseDragged(event);
}
void MenuHostRootView::OnMouseReleased(const MouseEvent& event,
bool canceled) {
if (suspend_events_)
return;
RootView::OnMouseReleased(event, canceled);
if (forward_drag_to_menu_controller_ && GetMenuController()) {
forward_drag_to_menu_controller_ = false;
if (canceled) {
GetMenuController()->Cancel(MenuController::EXIT_ALL);
} else {
GetMenuController()->OnMouseReleased(submenu_, event);
}
}
}
void MenuHostRootView::OnMouseMoved(const MouseEvent& event) {
if (suspend_events_)
return;
RootView::OnMouseMoved(event);
if (GetMenuController())
GetMenuController()->OnMouseMoved(submenu_, event);
}
bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& e) {
// 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(e);
}
void MenuHostRootView::ProcessOnMouseExited() {
if (suspend_events_)
return;
RootView::ProcessOnMouseExited();
}
MenuController* MenuHostRootView::GetMenuController() {
return submenu_->GetMenuItem()->GetMenuController();
}
} // namespace views
|