OLD | NEW |
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/focus_manager.h" | 5 #include "ui/aura/focus_manager.h" |
6 | 6 |
7 #include "ui/aura/client/activation_client.h" | 7 #include "ui/aura/client/activation_client.h" |
8 #include "ui/aura/focus_change_observer.h" | 8 #include "ui/aura/client/focus_change_observer.h" |
9 #include "ui/aura/window_delegate.h" | 9 #include "ui/aura/window_delegate.h" |
10 | 10 |
11 namespace aura { | 11 namespace aura { |
| 12 |
| 13 //////////////////////////////////////////////////////////////////////////////// |
| 14 // FocusManager, public: |
| 15 |
12 FocusManager::FocusManager() : focused_window_(NULL) { | 16 FocusManager::FocusManager() : focused_window_(NULL) { |
13 } | 17 } |
14 | 18 |
15 FocusManager::~FocusManager() { | 19 FocusManager::~FocusManager() { |
16 } | 20 } |
17 | 21 |
18 void FocusManager::AddObserver(FocusChangeObserver* observer) { | 22 //////////////////////////////////////////////////////////////////////////////// |
| 23 // FocusManager, client::FocusClient implementation: |
| 24 |
| 25 void FocusManager::AddObserver(client::FocusChangeObserver* observer) { |
19 observers_.AddObserver(observer); | 26 observers_.AddObserver(observer); |
20 } | 27 } |
21 | 28 |
22 void FocusManager::RemoveObserver(FocusChangeObserver* observer) { | 29 void FocusManager::RemoveObserver(client::FocusChangeObserver* observer) { |
23 observers_.RemoveObserver(observer); | 30 observers_.RemoveObserver(observer); |
24 } | 31 } |
25 | 32 |
26 void FocusManager::SetFocusedWindow(Window* focused_window, | 33 void FocusManager::FocusWindow(Window* focused_window, const ui::Event* event) { |
27 const ui::Event* event) { | |
28 if (focused_window == focused_window_) | 34 if (focused_window == focused_window_) |
29 return; | 35 return; |
30 if (focused_window && !focused_window->CanFocus()) | 36 if (focused_window && !focused_window->CanFocus()) |
31 return; | 37 return; |
32 // The NULL-check of |focused_window| is essential here before asking the | 38 // The NULL-check of |focused_window| is essential here before asking the |
33 // activation client, since it is valid to clear the focus by calling | 39 // activation client, since it is valid to clear the focus by calling |
34 // SetFocusedWindow() to NULL. | 40 // SetFocusedWindow() to NULL. |
35 | 41 |
36 if (focused_window) { | 42 if (focused_window) { |
37 RootWindow* root = focused_window->GetRootWindow(); | 43 RootWindow* root = focused_window->GetRootWindow(); |
38 DCHECK(root); | 44 DCHECK(root); |
39 if (client::GetActivationClient(root) && | 45 if (client::GetActivationClient(root) && |
40 !client::GetActivationClient(root)->OnWillFocusWindow( | 46 !client::GetActivationClient(root)->OnWillFocusWindow( |
41 focused_window, event)) { | 47 focused_window, event)) { |
42 return; | 48 return; |
43 } | 49 } |
44 } | 50 } |
45 | 51 |
46 Window* old_focused_window = focused_window_; | 52 Window* old_focused_window = focused_window_; |
47 focused_window_ = focused_window; | 53 focused_window_ = focused_window; |
48 if (old_focused_window && old_focused_window->delegate()) | 54 if (old_focused_window && old_focused_window->delegate()) |
49 old_focused_window->delegate()->OnBlur(); | 55 old_focused_window->delegate()->OnBlur(); |
50 if (focused_window_ && focused_window_->delegate()) | 56 if (focused_window_ && focused_window_->delegate()) |
51 focused_window_->delegate()->OnFocus(old_focused_window); | 57 focused_window_->delegate()->OnFocus(old_focused_window); |
52 if (focused_window_) { | 58 if (focused_window_) { |
53 FOR_EACH_OBSERVER(FocusChangeObserver, observers_, | 59 FOR_EACH_OBSERVER(client::FocusChangeObserver, observers_, |
54 OnWindowFocused(focused_window)); | 60 OnWindowFocused(focused_window)); |
55 } | 61 } |
56 } | 62 } |
57 | 63 |
58 Window* FocusManager::GetFocusedWindow() { | 64 Window* FocusManager::GetFocusedWindow() { |
59 return focused_window_; | 65 return focused_window_; |
60 } | 66 } |
61 | 67 |
62 bool FocusManager::IsFocusedWindow(const Window* window) const { | 68 } // namespace aura |
63 return focused_window_ == window; | |
64 } | |
65 | |
66 } // namespace ash | |
OLD | NEW |