Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: ui/views/widget/root_view.cc

Issue 6286013: V2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "ui/views/widget/root_view.h"
6
7 #include "ui/views/layout/fill_layout.h"
8 #include "ui/views/widget/widget.h"
9
10 namespace ui {
11 namespace internal {
12
13 ////////////////////////////////////////////////////////////////////////////////
14 // RootView, public:
15
16 RootView::RootView(Widget* widget, View* contents_view)
17 : widget_(widget),
18 mouse_pressed_handler_(NULL),
19 mouse_move_handler_(NULL) {
20 SetLayoutManager(new FillLayout);
21 AddChildView(contents_view);
22 }
23
24 RootView::~RootView() {
25 }
26
27 ////////////////////////////////////////////////////////////////////////////////
28 // RootView, View overrides:
29
30 void RootView::OnViewRemoved(View* parent, View* child) {
31 if (child == mouse_pressed_handler_)
32 mouse_pressed_handler_ = NULL;
33 }
34
35 bool RootView::OnKeyPressed(const KeyEvent& event) {
36 return true;
37 }
38
39 bool RootView::OnKeyReleased(const KeyEvent& event) {
40 return true;
41 }
42
43 bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
44 return true;
45 }
46
47 bool RootView::OnMousePressed(const MouseEvent& event) {
48 bool handled = false;
49
50 // Find the most View most tightly enclosing the event location that wants to
51 // handle events.
52 mouse_pressed_handler_ = GetViewForPoint(event.location());
53
54 // Walk up the tree from that View until we find one that handles it.
55 while (mouse_pressed_handler_ && mouse_pressed_handler_ != this) {
56 if (!mouse_pressed_handler_->enabled())
57 break;
58
59 MouseEvent target_event(event, this, mouse_pressed_handler_);
60 drag_info_.Reset();
61 bool handled = mouse_pressed_handler_->MousePressed(target_event,
62 &drag_info_);
63 // MousePressed() may have resulted in the handler removing itself from the
64 // hierarchy, which will NULL-out |mouse_pressed_handler_|.
65 if (!mouse_pressed_handler_)
66 break;
67
68 if (handled)
69 return true;
70
71 mouse_pressed_handler_ = mouse_pressed_handler_->parent();
72 }
73 return false;
74 }
75
76 bool RootView::OnMouseDragged(const MouseEvent& event) {
77 // TODO(beng): Update cursor.
78 if (mouse_pressed_handler_)
79 return mouse_pressed_handler_->MouseDragged(event, &drag_info_);
80 return false;
81 }
82
83 void RootView::OnMouseReleased(const MouseEvent& event) {
84 // TODO(beng): Update cursor.
85 if (mouse_pressed_handler_) {
86 MouseEvent released_event(event, this, mouse_pressed_handler_);
87 View* mouse_pressed_handler = mouse_pressed_handler_;
88 mouse_pressed_handler_ = NULL;
89 mouse_pressed_handler->MouseReleased(released_event);
90 }
91 }
92
93 void RootView::OnMouseCaptureLost() {
94 if (mouse_pressed_handler_) {
95 View* mouse_pressed_handler = mouse_pressed_handler_;
96 mouse_pressed_handler_ = NULL;
97 mouse_pressed_handler->OnMouseCaptureLost();
98 }
99 }
100
101 void RootView::OnMouseMoved(const MouseEvent& event) {
102 // TODO(beng): Update cursor.
103 View* v = GetViewForPoint(event.location());
104 while (v && !v->enabled() && (v != mouse_move_handler_))
105 v = v->parent();
106 if (v && v != this) {
107 if (v != mouse_move_handler_) {
108 OnMouseExited(event);
109 mouse_move_handler_ = v;
110 MouseEvent entered_event(event, this, mouse_move_handler_);
111 mouse_move_handler_->OnMouseEntered(entered_event);
112 }
113 MouseEvent moved_event(event, this, mouse_move_handler_);
114 mouse_move_handler_->OnMouseMoved(moved_event);
115 } else {
116 OnMouseExited(event);
117 }
118 }
119
120 void RootView::OnMouseExited(const MouseEvent& event) {
121 if (mouse_move_handler_) {
122 MouseEvent exited_event(event, this, mouse_move_handler_);
123 mouse_move_handler_->OnMouseExited(exited_event);
124 mouse_move_handler_ = NULL;
125 }
126 }
127
128 void RootView::Paint(gfx::Canvas* canvas) {
129 // Public pass-thru to protected base class method.
130 View::Paint(canvas);
131 }
132
133 void RootView::InvalidateRect(const gfx::Rect& invalid_rect) {
134 widget_->InvalidateRect(invalid_rect);
135 }
136
137 Widget* RootView::GetWidget() const {
138 return widget_;
139 }
140
141 ////////////////////////////////////////////////////////////////////////////////
142 // RootView, private:
143
144 } // namespace internal
145 } // namespace ui
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698