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

Unified Diff: ui/aura/root_window.cc

Issue 7976020: Wires up mouse capture code for aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix aura build Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/window.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/root_window.cc
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index f6b6b0256473aa4ea699523d851e793262b945a1..f4b0c2969e4ea00869cbc307d53fa79fa65c9a9e 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -17,7 +17,8 @@ namespace internal {
RootWindow::RootWindow()
: Window(NULL),
mouse_pressed_handler_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))),
+ capture_window_(NULL) {
set_name(ASCIIToUTF16("RootWindow"));
}
@@ -25,7 +26,8 @@ RootWindow::~RootWindow() {
}
bool RootWindow::HandleMouseEvent(const MouseEvent& event) {
- Window* target = mouse_pressed_handler_;
+ Window* target =
+ mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_;
if (!target)
target = GetEventHandlerForPoint(event.location());
if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_)
@@ -48,9 +50,52 @@ bool RootWindow::HandleKeyEvent(const KeyEvent& event) {
return false;
}
+void RootWindow::SetCapture(Window* window) {
+ if (capture_window_ == window)
+ return;
+
+ if (capture_window_ && capture_window_->delegate())
+ capture_window_->delegate()->OnCaptureLost();
+ capture_window_ = window;
+
+ if (capture_window_ && mouse_pressed_handler_) {
+ // Make all subsequent mouse events go to the capture window. We shouldn't
+ // need to send an event here as OnCaptureLost should take care of that.
+ mouse_pressed_handler_ = capture_window_;
+ }
+}
+
+void RootWindow::ReleaseCapture(Window* window) {
+ if (capture_window_ != window)
+ return;
+
+ if (capture_window_ && capture_window_->delegate())
+ capture_window_->delegate()->OnCaptureLost();
+ capture_window_ = NULL;
+}
+
+void RootWindow::WindowDestroying(Window* window) {
+ // Update the FocusManager if the window was focused.
+ internal::FocusManager* focus_manager = GetFocusManager();
+ if (focus_manager && focus_manager->focused_window() == window)
+ focus_manager->SetFocusedWindow(NULL);
+
+ // When a window is being destroyed it's likely that the WindowDelegate won't
+ // want events, so we reset the mouse_pressed_handler_ and capture_window_ and
+ // don't sent it release/capture lost events.
+ if (mouse_pressed_handler_ == window)
+ mouse_pressed_handler_ = NULL;
+ if (capture_window_ == window)
+ capture_window_ = NULL;
+}
+
FocusManager* RootWindow::GetFocusManager() {
return focus_manager_.get();
}
+internal::RootWindow* RootWindow::GetRoot() {
+ return this;
+}
+
} // namespace internal
} // namespace aura
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698