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 "ash/magnifier/partial_magnification_controller.h" | 5 #include "ash/magnifier/partial_magnification_controller.h" |
6 | 6 |
7 #include "ash/common/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura/window_event_dispatcher.h" | 10 #include "ui/aura/window_event_dispatcher.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 SwitchTargetRootWindow(current_root); | 87 SwitchTargetRootWindow(current_root); |
88 | 88 |
89 OnMouseMove(event->root_location()); | 89 OnMouseMove(event->root_location()); |
90 } | 90 } |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
95 // PartialMagnificationController: aura::WindowObserver implementation | 95 // PartialMagnificationController: aura::WindowObserver implementation |
96 | 96 |
97 void PartialMagnificationController::OnWindowDestroying( | 97 void PartialMagnificationController::OnWindowDestroying(aura::Window* window) { |
98 aura::Window* window) { | |
99 CloseMagnifierWindow(); | 98 CloseMagnifierWindow(); |
100 | 99 |
101 aura::Window* new_root_window = GetCurrentRootWindow(); | 100 aura::Window* new_root_window = GetCurrentRootWindow(); |
102 if (new_root_window != window) | 101 if (new_root_window != window) |
103 SwitchTargetRootWindow(new_root_window); | 102 SwitchTargetRootWindow(new_root_window); |
104 } | 103 } |
105 | 104 |
106 void PartialMagnificationController::OnWidgetDestroying( | 105 void PartialMagnificationController::OnWidgetDestroying(views::Widget* widget) { |
107 views::Widget* widget) { | |
108 DCHECK_EQ(widget, zoom_widget_); | 106 DCHECK_EQ(widget, zoom_widget_); |
109 RemoveZoomWidgetObservers(); | 107 RemoveZoomWidgetObservers(); |
110 zoom_widget_ = NULL; | 108 zoom_widget_ = NULL; |
111 } | 109 } |
112 | 110 |
113 void PartialMagnificationController::OnMouseMove( | 111 void PartialMagnificationController::OnMouseMove( |
114 const gfx::Point& location_in_root) { | 112 const gfx::Point& location_in_root) { |
115 gfx::Point origin(location_in_root); | 113 gfx::Point origin(location_in_root); |
116 | 114 |
117 origin.Offset(-kMagnifierWidth / 2, -kMagnifierHeight / 2); | 115 origin.Offset(-kMagnifierWidth / 2, -kMagnifierHeight / 2); |
118 | 116 |
119 if (zoom_widget_) { | 117 if (zoom_widget_) { |
120 zoom_widget_->SetBounds(gfx::Rect(origin.x(), origin.y(), | 118 zoom_widget_->SetBounds( |
121 kMagnifierWidth, kMagnifierHeight)); | 119 gfx::Rect(origin.x(), origin.y(), kMagnifierWidth, kMagnifierHeight)); |
122 } | 120 } |
123 } | 121 } |
124 | 122 |
125 bool PartialMagnificationController::IsPartialMagnified() const { | 123 bool PartialMagnificationController::IsPartialMagnified() const { |
126 return scale_ >= kMinPartialMagnifiedScaleThreshold; | 124 return scale_ >= kMinPartialMagnifiedScaleThreshold; |
127 } | 125 } |
128 | 126 |
129 void PartialMagnificationController::CreateMagnifierWindow() { | 127 void PartialMagnificationController::CreateMagnifierWindow() { |
130 if (zoom_widget_) | 128 if (zoom_widget_) |
131 return; | 129 return; |
(...skipping 18 matching lines...) Expand all Loading... |
150 zoom_widget_->SetBounds(gfx::Rect(mouse.x() - kMagnifierWidth / 2, | 148 zoom_widget_->SetBounds(gfx::Rect(mouse.x() - kMagnifierWidth / 2, |
151 mouse.y() - kMagnifierHeight / 2, | 149 mouse.y() - kMagnifierHeight / 2, |
152 kMagnifierWidth, kMagnifierHeight)); | 150 kMagnifierWidth, kMagnifierHeight)); |
153 zoom_widget_->set_focus_on_creation(false); | 151 zoom_widget_->set_focus_on_creation(false); |
154 zoom_widget_->Show(); | 152 zoom_widget_->Show(); |
155 | 153 |
156 aura::Window* window = zoom_widget_->GetNativeView(); | 154 aura::Window* window = zoom_widget_->GetNativeView(); |
157 window->SetName(kPartialMagniferWindowName); | 155 window->SetName(kPartialMagniferWindowName); |
158 | 156 |
159 zoom_widget_->GetNativeView()->layer()->SetBounds( | 157 zoom_widget_->GetNativeView()->layer()->SetBounds( |
160 gfx::Rect(0, 0, | 158 gfx::Rect(0, 0, kMagnifierWidth, kMagnifierHeight)); |
161 kMagnifierWidth, | 159 zoom_widget_->GetNativeView()->layer()->SetBackgroundZoom(scale_, kZoomInset); |
162 kMagnifierHeight)); | |
163 zoom_widget_->GetNativeView()->layer()->SetBackgroundZoom( | |
164 scale_, | |
165 kZoomInset); | |
166 | 160 |
167 zoom_widget_->AddObserver(this); | 161 zoom_widget_->AddObserver(this); |
168 } | 162 } |
169 | 163 |
170 void PartialMagnificationController::CloseMagnifierWindow() { | 164 void PartialMagnificationController::CloseMagnifierWindow() { |
171 if (zoom_widget_) { | 165 if (zoom_widget_) { |
172 RemoveZoomWidgetObservers(); | 166 RemoveZoomWidgetObservers(); |
173 zoom_widget_->Close(); | 167 zoom_widget_->Close(); |
174 zoom_widget_ = NULL; | 168 zoom_widget_ = NULL; |
175 } | 169 } |
176 } | 170 } |
177 | 171 |
178 void PartialMagnificationController::RemoveZoomWidgetObservers() { | 172 void PartialMagnificationController::RemoveZoomWidgetObservers() { |
179 DCHECK(zoom_widget_); | 173 DCHECK(zoom_widget_); |
180 zoom_widget_->RemoveObserver(this); | 174 zoom_widget_->RemoveObserver(this); |
181 aura::Window* root_window = | 175 aura::Window* root_window = zoom_widget_->GetNativeView()->GetRootWindow(); |
182 zoom_widget_->GetNativeView()->GetRootWindow(); | |
183 DCHECK(root_window); | 176 DCHECK(root_window); |
184 root_window->RemoveObserver(this); | 177 root_window->RemoveObserver(this); |
185 } | 178 } |
186 | 179 |
187 void PartialMagnificationController::SwitchTargetRootWindow( | 180 void PartialMagnificationController::SwitchTargetRootWindow( |
188 aura::Window* new_root_window) { | 181 aura::Window* new_root_window) { |
189 if (zoom_widget_ && | 182 if (zoom_widget_ && |
190 new_root_window == zoom_widget_->GetNativeView()->GetRootWindow()) | 183 new_root_window == zoom_widget_->GetNativeView()->GetRootWindow()) |
191 return; | 184 return; |
192 | 185 |
193 CloseMagnifierWindow(); | 186 CloseMagnifierWindow(); |
194 | 187 |
195 // Recreate the magnifier window by updating the scale factor. | 188 // Recreate the magnifier window by updating the scale factor. |
196 SetScale(GetScale()); | 189 SetScale(GetScale()); |
197 } | 190 } |
198 | 191 |
199 aura::Window* PartialMagnificationController::GetCurrentRootWindow() { | 192 aura::Window* PartialMagnificationController::GetCurrentRootWindow() { |
200 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 193 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
201 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | 194 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
202 iter != root_windows.end(); ++iter) { | 195 iter != root_windows.end(); ++iter) { |
203 aura::Window* root_window = *iter; | 196 aura::Window* root_window = *iter; |
204 if (root_window->ContainsPointInRoot( | 197 if (root_window->ContainsPointInRoot( |
205 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot())) | 198 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot())) |
206 return root_window; | 199 return root_window; |
207 } | 200 } |
208 return NULL; | 201 return NULL; |
209 } | 202 } |
210 | 203 |
211 } // namespace ash | 204 } // namespace ash |
OLD | NEW |