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

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

Issue 11299219: Rework FocusManager as FocusClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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/window.h ('k') | ui/views/controls/native/native_view_host_aura.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 Window* Window::GetToplevelWindow() { 518 Window* Window::GetToplevelWindow() {
519 Window* topmost_window_with_delegate = NULL; 519 Window* topmost_window_with_delegate = NULL;
520 for (aura::Window* window = this; window != NULL; window = window->parent()) { 520 for (aura::Window* window = this; window != NULL; window = window->parent()) {
521 if (window->delegate()) 521 if (window->delegate())
522 topmost_window_with_delegate = window; 522 topmost_window_with_delegate = window;
523 } 523 }
524 return topmost_window_with_delegate; 524 return topmost_window_with_delegate;
525 } 525 }
526 526
527 void Window::Focus() { 527 void Window::Focus() {
528 DCHECK(GetFocusManager()); 528 client::FocusClient* client = client::GetFocusClient(this);
529 GetFocusManager()->SetFocusedWindow(this, NULL); 529 DCHECK(client);
530 client->FocusWindow(this, NULL);
530 } 531 }
531 532
532 void Window::Blur() { 533 void Window::Blur() {
533 DCHECK(GetFocusManager()); 534 client::FocusClient* client = client::GetFocusClient(this);
534 GetFocusManager()->SetFocusedWindow(NULL, NULL); 535 DCHECK(client);
536 client->FocusWindow(NULL, NULL);
535 } 537 }
536 538
537 bool Window::HasFocus() const { 539 bool Window::HasFocus() const {
538 const FocusManager* focus_manager = GetFocusManager(); 540 client::FocusClient* client = client::GetFocusClient(this);
539 return focus_manager ? focus_manager->IsFocusedWindow(this) : false; 541 return client ? client->GetFocusedWindow() == this : false;
sky 2012/11/28 00:20:13 nit: return client && client->Getfocusedwindow() =
540 } 542 }
541 543
542 bool Window::CanFocus() const { 544 bool Window::CanFocus() const {
543 // NOTE: as part of focusing the window the ActivationClient may make the 545 // NOTE: as part of focusing the window the ActivationClient may make the
544 // window visible (by way of making a hidden ancestor visible). For this 546 // window visible (by way of making a hidden ancestor visible). For this
545 // reason we can't check visibility here and assume the client is doing it. 547 // reason we can't check visibility here and assume the client is doing it.
546 if (!parent_ || (delegate_ && !delegate_->CanFocus())) 548 if (!parent_ || (delegate_ && !delegate_->CanFocus()))
547 return false; 549 return false;
548 550
549 // The client may forbid certain windows from receiving focus at a given point 551 // The client may forbid certain windows from receiving focus at a given point
550 // in time. 552 // in time.
551 client::EventClient* client = client::GetEventClient(GetRootWindow()); 553 client::EventClient* client = client::GetEventClient(GetRootWindow());
552 if (client && !client->CanProcessEventsWithinSubtree(this)) 554 if (client && !client->CanProcessEventsWithinSubtree(this))
553 return false; 555 return false;
554 556
555 return parent_->CanFocus(); 557 return parent_->CanFocus();
556 } 558 }
557 559
558 bool Window::CanReceiveEvents() const { 560 bool Window::CanReceiveEvents() const {
559 // The client may forbid certain windows from receiving events at a given 561 // The client may forbid certain windows from receiving events at a given
560 // point in time. 562 // point in time.
561 client::EventClient* client = client::GetEventClient(GetRootWindow()); 563 client::EventClient* client = client::GetEventClient(GetRootWindow());
562 if (client && !client->CanProcessEventsWithinSubtree(this)) 564 if (client && !client->CanProcessEventsWithinSubtree(this))
563 return false; 565 return false;
564 566
565 return parent_ && IsVisible() && parent_->CanReceiveEvents(); 567 return parent_ && IsVisible() && parent_->CanReceiveEvents();
566 } 568 }
567 569
568 FocusManager* Window::GetFocusManager() {
569 return const_cast<FocusManager*>(
570 static_cast<const Window*>(this)->GetFocusManager());
571 }
572
573 const FocusManager* Window::GetFocusManager() const {
574 return parent_ ? parent_->GetFocusManager() : NULL;
575 }
576
577 void Window::SetCapture() { 570 void Window::SetCapture() {
578 if (!IsVisible()) 571 if (!IsVisible())
579 return; 572 return;
580 573
581 RootWindow* root_window = GetRootWindow(); 574 RootWindow* root_window = GetRootWindow();
582 if (!root_window) 575 if (!root_window)
583 return; 576 return;
584 client::GetCaptureClient(root_window)->SetCapture(this); 577 client::GetCaptureClient(root_window)->SetCapture(this);
585 } 578 }
586 579
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 bool contains_mouse = false; 964 bool contains_mouse = false;
972 if (IsVisible()) { 965 if (IsVisible()) {
973 RootWindow* root_window = GetRootWindow(); 966 RootWindow* root_window = GetRootWindow();
974 contains_mouse = root_window && 967 contains_mouse = root_window &&
975 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); 968 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot());
976 } 969 }
977 return contains_mouse; 970 return contains_mouse;
978 } 971 }
979 972
980 } // namespace aura 973 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.h ('k') | ui/views/controls/native/native_view_host_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698