| 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/views/widget/desktop_aura/desktop_activation_client.h" | 5 #include "ui/views/widget/desktop_aura/desktop_activation_client.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "ui/aura/client/activation_delegate.h" | 9 #include "ui/aura/client/activation_delegate.h" |
| 10 #include "ui/aura/client/activation_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 void DesktopActivationClient::DeactivateWindow(aura::Window* window) { | 94 void DesktopActivationClient::DeactivateWindow(aura::Window* window) { |
| 95 if (window == current_active_) | 95 if (window == current_active_) |
| 96 current_active_ = NULL; | 96 current_active_ = NULL; |
| 97 } | 97 } |
| 98 | 98 |
| 99 aura::Window* DesktopActivationClient::GetActiveWindow() { | 99 aura::Window* DesktopActivationClient::GetActiveWindow() { |
| 100 return current_active_; | 100 return current_active_; |
| 101 } | 101 } |
| 102 | 102 |
| 103 aura::Window* DesktopActivationClient::GetActivatableWindow( |
| 104 aura::Window* window) { |
| 105 aura::Window* parent = window->parent(); |
| 106 aura::Window* child = window; |
| 107 while (parent) { |
| 108 if (CanActivateWindow(child)) |
| 109 return child; |
| 110 // If |child| isn't activatable, but has transient parent, trace |
| 111 // that path instead. |
| 112 if (child->transient_parent()) |
| 113 return GetActivatableWindow(child->transient_parent()); |
| 114 parent = parent->parent(); |
| 115 child = child->parent(); |
| 116 } |
| 117 return NULL; |
| 118 } |
| 119 |
| 103 bool DesktopActivationClient::OnWillFocusWindow(aura::Window* window, | 120 bool DesktopActivationClient::OnWillFocusWindow(aura::Window* window, |
| 104 const ui::Event* event) { | 121 const ui::Event* event) { |
| 105 return CanActivateWindow(GetActivatableWindow(window)); | 122 return CanActivateWindow(GetActivatableWindow(window)); |
| 106 } | 123 } |
| 107 | 124 |
| 108 void DesktopActivationClient::OnWindowDestroying(aura::Window* window) { | 125 void DesktopActivationClient::OnWindowDestroying(aura::Window* window) { |
| 109 if (current_active_ == window) { | 126 if (current_active_ == window) { |
| 110 current_active_ = NULL; | 127 current_active_ = NULL; |
| 111 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 128 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, |
| 112 observers_, | 129 observers_, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 166 |
| 150 ui::EventResult DesktopActivationClient::OnGestureEvent( | 167 ui::EventResult DesktopActivationClient::OnGestureEvent( |
| 151 ui::GestureEvent* event) { | 168 ui::GestureEvent* event) { |
| 152 if (event->type() == ui::ET_GESTURE_BEGIN && | 169 if (event->type() == ui::ET_GESTURE_BEGIN && |
| 153 event->details().touch_points() == 1) { | 170 event->details().touch_points() == 1) { |
| 154 FocusWindowWithEvent(event); | 171 FocusWindowWithEvent(event); |
| 155 } | 172 } |
| 156 return ui::ER_UNHANDLED; | 173 return ui::ER_UNHANDLED; |
| 157 } | 174 } |
| 158 | 175 |
| 159 aura::Window* DesktopActivationClient::GetActivatableWindow( | |
| 160 aura::Window* window) { | |
| 161 aura::Window* parent = window->parent(); | |
| 162 aura::Window* child = window; | |
| 163 while (parent) { | |
| 164 if (CanActivateWindow(child)) | |
| 165 return child; | |
| 166 // If |child| isn't activatable, but has transient parent, trace | |
| 167 // that path instead. | |
| 168 if (child->transient_parent()) | |
| 169 return GetActivatableWindow(child->transient_parent()); | |
| 170 parent = parent->parent(); | |
| 171 child = child->parent(); | |
| 172 } | |
| 173 return NULL; | |
| 174 } | |
| 175 | |
| 176 void DesktopActivationClient::FocusWindowWithEvent(const ui::Event* event) { | 176 void DesktopActivationClient::FocusWindowWithEvent(const ui::Event* event) { |
| 177 aura::Window* window = static_cast<aura::Window*>(event->target()); | 177 aura::Window* window = static_cast<aura::Window*>(event->target()); |
| 178 if (GetActiveWindow() != window) { | 178 if (GetActiveWindow() != window) { |
| 179 aura::client::GetFocusClient(window)->FocusWindow( | 179 aura::client::GetFocusClient(window)->FocusWindow( |
| 180 FindFocusableWindowFor(window), event); | 180 FindFocusableWindowFor(window), event); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace views | 184 } // namespace views |
| OLD | NEW |