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

Side by Side Diff: ui/aura/root_window.cc

Issue 8894018: Move the concept of Activation to the Shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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/aura/root_window.h ('k') | ui/aura/root_window_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "ui/aura/aura_switches.h" 16 #include "ui/aura/aura_switches.h"
17 #include "ui/aura/client/activation_client.h"
17 #include "ui/aura/client/drag_drop_client.h" 18 #include "ui/aura/client/drag_drop_client.h"
18 #include "ui/aura/client/stacking_client.h" 19 #include "ui/aura/client/stacking_client.h"
19 #include "ui/aura/client/tooltip_client.h" 20 #include "ui/aura/client/tooltip_client.h"
20 #include "ui/aura/client/window_drag_drop_delegate.h" 21 #include "ui/aura/client/window_drag_drop_delegate.h"
21 #include "ui/aura/root_window_host.h" 22 #include "ui/aura/root_window_host.h"
22 #include "ui/aura/root_window_observer.h" 23 #include "ui/aura/root_window_observer.h"
23 #include "ui/aura/event.h" 24 #include "ui/aura/event.h"
24 #include "ui/aura/event_filter.h" 25 #include "ui/aura/event_filter.h"
25 #include "ui/aura/focus_manager.h" 26 #include "ui/aura/focus_manager.h"
26 #include "ui/aura/screen_aura.h" 27 #include "ui/aura/screen_aura.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 explicit DefaultStackingClient(RootWindow* root_window) 63 explicit DefaultStackingClient(RootWindow* root_window)
63 : root_window_(root_window) {} 64 : root_window_(root_window) {}
64 virtual ~DefaultStackingClient() {} 65 virtual ~DefaultStackingClient() {}
65 66
66 private: 67 private:
67 68
68 // Overridden from StackingClient: 69 // Overridden from StackingClient:
69 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { 70 virtual void AddChildToDefaultParent(Window* window) OVERRIDE {
70 root_window_->AddChild(window); 71 root_window_->AddChild(window);
71 } 72 }
72 virtual bool CanActivateWindow(Window* window) const OVERRIDE {
73 return window->parent() == root_window_;
74 }
75 virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE {
76 Window::Windows::const_reverse_iterator i;
77 for (i = root_window_->children().rbegin();
78 i != root_window_->children().rend();
79 ++i) {
80 if (*i == ignore)
81 continue;
82 return *i;
83 }
84 return NULL;
85 }
86 73
87 RootWindow* root_window_; 74 RootWindow* root_window_;
88 75
89 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); 76 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient);
90 }; 77 };
91 78
92 typedef std::vector<EventFilter*> EventFilters; 79 typedef std::vector<EventFilter*> EventFilters;
93 80
94 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { 81 void GetEventFiltersToNotify(Window* target, EventFilters* filters) {
95 Window* window = target->parent(); 82 Window* window = target->parent();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 SetBounds(gfx::Rect(bounds.size())); 227 SetBounds(gfx::Rect(bounds.size()));
241 FOR_EACH_OBSERVER(RootWindowObserver, observers_, 228 FOR_EACH_OBSERVER(RootWindowObserver, observers_,
242 OnRootWindowResized(bounds.size())); 229 OnRootWindowResized(bounds.size()));
243 } 230 }
244 231
245 void RootWindow::OnNativeScreenResized(const gfx::Size& size) { 232 void RootWindow::OnNativeScreenResized(const gfx::Size& size) {
246 if (use_fullscreen_host_window_) 233 if (use_fullscreen_host_window_)
247 SetHostSize(size); 234 SetHostSize(size);
248 } 235 }
249 236
250 void RootWindow::SetActiveWindow(Window* window, Window* to_focus) {
251 if (!window)
252 return;
253 // The stacking client may impose rules on what window configurations can be
254 // activated or deactivated.
255 if (!stacking_client_->CanActivateWindow(window))
256 return;
257 // The window may not be activate-able.
258 if (!window->CanActivate())
259 return;
260 // Nothing may actually have changed.
261 if (active_window_ == window)
262 return;
263
264 Window* old_active = active_window_;
265 active_window_ = window;
266 // Invoke OnLostActive after we've changed the active window. That way if the
267 // delegate queries for active state it doesn't think the window is still
268 // active.
269 if (old_active && old_active->delegate())
270 old_active->delegate()->OnLostActive();
271 if (active_window_) {
272 active_window_->parent()->StackChildAtTop(active_window_);
273 if (active_window_->delegate())
274 active_window_->delegate()->OnActivated();
275 active_window_->GetFocusManager()->SetFocusedWindow(
276 to_focus ? to_focus : active_window_);
277 }
278 FOR_EACH_OBSERVER(RootWindowObserver, observers_,
279 OnActiveWindowChanged(active_window_));
280 }
281
282 void RootWindow::ActivateTopmostWindow() {
283 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(NULL), NULL);
284 }
285
286 void RootWindow::Deactivate(Window* window) {
287 // The stacking client may impose rules on what window configurations can be
288 // activated or deactivated.
289 if (!window || !stacking_client_->CanActivateWindow(window))
290 return;
291 if (active_window_ != window)
292 return;
293
294 Window* to_activate = stacking_client_->GetTopmostWindowToActivate(window);
295 if (to_activate)
296 SetActiveWindow(to_activate, NULL);
297 }
298
299 void RootWindow::WindowInitialized(Window* window) { 237 void RootWindow::WindowInitialized(Window* window) {
300 FOR_EACH_OBSERVER(RootWindowObserver, observers_, 238 FOR_EACH_OBSERVER(RootWindowObserver, observers_,
301 OnWindowInitialized(window)); 239 OnWindowInitialized(window));
302 } 240 }
303 241
304 void RootWindow::WindowDestroying(Window* window) { 242 void RootWindow::WindowDestroying(Window* window) {
305 // Update the focused window state if the window was focused. 243 // Update the focused window state if the window was focused.
306 if (focused_window_ == window) 244 if (focused_window_ == window)
307 SetFocusedWindow(NULL); 245 SetFocusedWindow(NULL);
308 246
309 // When a window is being destroyed it's likely that the WindowDelegate won't 247 // When a window is being destroyed it's likely that the WindowDelegate won't
310 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and 248 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and
311 // don't sent it release/capture lost events. 249 // don't sent it release/capture lost events.
312 if (mouse_pressed_handler_ == window) 250 if (mouse_pressed_handler_ == window)
313 mouse_pressed_handler_ = NULL; 251 mouse_pressed_handler_ = NULL;
314 if (mouse_moved_handler_ == window) 252 if (mouse_moved_handler_ == window)
315 mouse_moved_handler_ = NULL; 253 mouse_moved_handler_ = NULL;
316 if (capture_window_ == window) 254 if (capture_window_ == window)
317 capture_window_ = NULL; 255 capture_window_ = NULL;
318 if (touch_event_handler_ == window) 256 if (touch_event_handler_ == window)
319 touch_event_handler_ = NULL; 257 touch_event_handler_ = NULL;
320
321 if (in_destructor_ || window != active_window_)
322 return;
323
324 // Reset active_window_ before invoking SetActiveWindow so that we don't
325 // attempt to notify it while running its destructor.
326 active_window_ = NULL;
327 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(window), NULL);
328 } 258 }
329 259
330 MessageLoop::Dispatcher* RootWindow::GetDispatcher() { 260 MessageLoop::Dispatcher* RootWindow::GetDispatcher() {
331 return host_.get(); 261 return host_.get();
332 } 262 }
333 263
334 void RootWindow::AddObserver(RootWindowObserver* observer) { 264 void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) {
335 observers_.AddObserver(observer); 265 observers_.AddObserver(observer);
336 } 266 }
337 267
338 void RootWindow::RemoveObserver(RootWindowObserver* observer) { 268 void RootWindow::RemoveRootWindowObserver(RootWindowObserver* observer) {
339 observers_.RemoveObserver(observer); 269 observers_.RemoveObserver(observer);
340 } 270 }
341 271
342 bool RootWindow::IsMouseButtonDown() const { 272 bool RootWindow::IsMouseButtonDown() const {
343 return mouse_button_flags_ != 0; 273 return mouse_button_flags_ != 0;
344 } 274 }
345 275
346 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { 276 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) {
347 host_->PostNativeEvent(native_event); 277 host_->PostNativeEvent(native_event);
348 } 278 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 329
400 //////////////////////////////////////////////////////////////////////////////// 330 ////////////////////////////////////////////////////////////////////////////////
401 // RootWindow, private: 331 // RootWindow, private:
402 332
403 RootWindow::RootWindow() 333 RootWindow::RootWindow()
404 : Window(NULL), 334 : Window(NULL),
405 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), 335 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())),
406 ALLOW_THIS_IN_INITIALIZER_LIST( 336 ALLOW_THIS_IN_INITIALIZER_LIST(
407 stacking_client_(new DefaultStackingClient(this))), 337 stacking_client_(new DefaultStackingClient(this))),
408 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), 338 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)),
409 active_window_(NULL),
410 mouse_button_flags_(0), 339 mouse_button_flags_(0),
411 last_cursor_(kCursorNull), 340 last_cursor_(kCursorNull),
412 in_destructor_(false),
413 screen_(new ScreenAura), 341 screen_(new ScreenAura),
414 capture_window_(NULL), 342 capture_window_(NULL),
415 mouse_pressed_handler_(NULL), 343 mouse_pressed_handler_(NULL),
416 mouse_moved_handler_(NULL), 344 mouse_moved_handler_(NULL),
417 focused_window_(NULL), 345 focused_window_(NULL),
418 touch_event_handler_(NULL) { 346 touch_event_handler_(NULL) {
419 SetName("RootWindow"); 347 SetName("RootWindow");
420 gfx::Screen::SetInstance(screen_); 348 gfx::Screen::SetInstance(screen_);
421 host_->SetRootWindow(this); 349 host_->SetRootWindow(this);
422 last_mouse_location_ = host_->QueryMouseLocation(); 350 last_mouse_location_ = host_->QueryMouseLocation();
423 351
424 if (ui::Compositor::compositor_factory()) { 352 if (ui::Compositor::compositor_factory()) {
425 compositor_ = (*ui::Compositor::compositor_factory())(this); 353 compositor_ = (*ui::Compositor::compositor_factory())(this);
426 } else { 354 } else {
427 #ifdef USE_WEBKIT_COMPOSITOR 355 #ifdef USE_WEBKIT_COMPOSITOR
428 ui::CompositorCC::Initialize(false); 356 ui::CompositorCC::Initialize(false);
429 #endif 357 #endif
430 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), 358 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
431 host_->GetSize()); 359 host_->GetSize());
432 } 360 }
433 DCHECK(compositor_.get()); 361 DCHECK(compositor_.get());
434 } 362 }
435 363
436 RootWindow::~RootWindow() { 364 RootWindow::~RootWindow() {
437 in_destructor_ = true;
438 // Make sure to destroy the compositor before terminating so that state is 365 // Make sure to destroy the compositor before terminating so that state is
439 // cleared and we don't hit asserts. 366 // cleared and we don't hit asserts.
440 compositor_ = NULL; 367 compositor_ = NULL;
441 // An observer may have been added by an animation on the RootWindow. 368 // An observer may have been added by an animation on the RootWindow.
442 layer()->GetAnimator()->RemoveObserver(this); 369 layer()->GetAnimator()->RemoveObserver(this);
443 #ifdef USE_WEBKIT_COMPOSITOR 370 #ifdef USE_WEBKIT_COMPOSITOR
444 if (!ui::Compositor::compositor_factory()) 371 if (!ui::Compositor::compositor_factory())
445 ui::CompositorCC::Terminate(); 372 ui::CompositorCC::Terminate();
446 #endif 373 #endif
447 if (instance_ == this) 374 if (instance_ == this)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 491
565 void RootWindow::OnLayerAnimationScheduled( 492 void RootWindow::OnLayerAnimationScheduled(
566 const ui::LayerAnimationSequence* animation) { 493 const ui::LayerAnimationSequence* animation) {
567 } 494 }
568 495
569 void RootWindow::OnLayerAnimationAborted( 496 void RootWindow::OnLayerAnimationAborted(
570 const ui::LayerAnimationSequence* animation) { 497 const ui::LayerAnimationSequence* animation) {
571 } 498 }
572 499
573 void RootWindow::SetFocusedWindow(Window* focused_window) { 500 void RootWindow::SetFocusedWindow(Window* focused_window) {
574 if (focused_window == focused_window_ || 501 if (focused_window == focused_window_)
575 (focused_window && !focused_window->CanFocus())) { 502 return;
503 if (focused_window && !focused_window->CanFocus())
504 return;
505 // The NULL-check of |focused)window| is essential here before asking the
506 // activation client, since it is valid to clear the focus by calling
507 // SetFocusedWindow() to NULL.
508 if (focused_window && ActivationClient::GetActivationClient() &&
509 !ActivationClient::GetActivationClient()->CanFocusWindow(
510 focused_window)) {
576 return; 511 return;
577 } 512 }
513
578 if (focused_window_ && focused_window_->delegate()) 514 if (focused_window_ && focused_window_->delegate())
579 focused_window_->delegate()->OnBlur(); 515 focused_window_->delegate()->OnBlur();
580 focused_window_ = focused_window; 516 focused_window_ = focused_window;
581 if (focused_window_ && focused_window_->delegate()) 517 if (focused_window_ && focused_window_->delegate())
582 focused_window_->delegate()->OnFocus(); 518 focused_window_->delegate()->OnFocus();
519 if (focused_window_) {
520 FOR_EACH_OBSERVER(RootWindowObserver, observers_,
521 OnWindowFocused(focused_window_));
522 }
583 } 523 }
584 524
585 Window* RootWindow::GetFocusedWindow() { 525 Window* RootWindow::GetFocusedWindow() {
586 return focused_window_; 526 return focused_window_;
587 } 527 }
588 528
589 bool RootWindow::IsFocusedWindow(const Window* window) const { 529 bool RootWindow::IsFocusedWindow(const Window* window) const {
590 return focused_window_ == window; 530 return focused_window_ == window;
591 } 531 }
592 532
(...skipping 18 matching lines...) Expand all
611 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { 551 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) {
612 bounds.set_size(gfx::Size(parsed_width, parsed_height)); 552 bounds.set_size(gfx::Size(parsed_width, parsed_height));
613 } else if (use_fullscreen_host_window_) { 553 } else if (use_fullscreen_host_window_) {
614 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); 554 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize());
615 } 555 }
616 556
617 return bounds; 557 return bounds;
618 } 558 }
619 559
620 } // namespace aura 560 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/root_window_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698