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/shell.h" | 7 #include "ash/shell.h" |
8 #include "ui/aura/window_event_dispatcher.h" | 8 #include "ui/aura/window_event_dispatcher.h" |
9 #include "ui/aura/window_tree_host.h" | 9 #include "ui/aura/window_tree_host.h" |
10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
11 #include "ui/compositor/paint_recorder.h" | 11 #include "ui/compositor/paint_recorder.h" |
12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
13 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
14 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
15 #include "ui/wm/core/coordinate_conversion.h" | 15 #include "ui/wm/core/coordinate_conversion.h" |
16 | 16 |
17 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
18 #include "ash/common/system/chromeos/palette/palette_utils.h" | 18 #include "ash/common/system/chromeos/palette/palette_utils.h" |
19 #endif | 19 #endif |
20 | 20 |
21 namespace ash { | 21 namespace ash { |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Ratio of magnifier scale. | 24 // Ratio of magnifier scale. |
25 const float kMagnificationScale = 2.f; | 25 const float kMagnificationScale = 2.f; |
26 // Radius of the magnifying glass in DIP. | 26 // Radius of the magnifying glass in DIP. |
27 const int kMagnifierRadius = 200; | 27 const int kMagnifierRadius = 200; |
28 // Size of the border around the magnifying glass in DIP. | 28 // Size of the border around the magnifying glass in DIP. |
29 const int kBorderSize = 10; | 29 const int kBorderSize = 10; |
30 // Thickness of the outline around magnifying glass border in DIP. | |
31 const int kBorderOutlineThickness = 2; | |
32 // The color of the border an its outlines. The border has an outline on both | |
James Cook
2016/09/14 20:54:00
nit: an -> and
sammiequon
2016/09/14 21:53:51
Done.
| |
33 // sides, producing a black/white/black ring. | |
34 const SkColor kBorderColor = SK_ColorWHITE; | |
35 const SkColor kBorderOutlineColor = SK_ColorBLACK; | |
30 // Inset on the zoom filter. | 36 // Inset on the zoom filter. |
31 const int kZoomInset = 0; | 37 const int kZoomInset = 0; |
32 // Vertical offset between the center of the magnifier and the tip of the | 38 // Vertical offset between the center of the magnifier and the tip of the |
33 // pointer. TODO(jdufault): The vertical offset should only apply to the window | 39 // pointer. TODO(jdufault): The vertical offset should only apply to the window |
34 // location, not the magnified contents. See crbug.com/637617. | 40 // location, not the magnified contents. See crbug.com/637617. |
35 const int kVerticalOffset = 0; | 41 const int kVerticalOffset = 0; |
36 | 42 |
37 // Name of the magnifier window. | 43 // Name of the magnifier window. |
38 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; | 44 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; |
39 | 45 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 layer_.set_delegate(this); | 87 layer_.set_delegate(this); |
82 layer_.SetFillsBoundsOpaquely(false); | 88 layer_.SetFillsBoundsOpaquely(false); |
83 layer_.SetBounds(gfx::Rect(mask_bounds)); | 89 layer_.SetBounds(gfx::Rect(mask_bounds)); |
84 } | 90 } |
85 | 91 |
86 ~ContentMask() override { layer_.set_delegate(nullptr); } | 92 ~ContentMask() override { layer_.set_delegate(nullptr); } |
87 | 93 |
88 ui::Layer* layer() { return &layer_; } | 94 ui::Layer* layer() { return &layer_; } |
89 | 95 |
90 private: | 96 private: |
91 // Overridden from LayerDelegate. | 97 // ui::LayerDelegate: |
92 void OnPaintLayer(const ui::PaintContext& context) override { | 98 void OnPaintLayer(const ui::PaintContext& context) override { |
93 ui::PaintRecorder recorder(context, layer()->size()); | 99 ui::PaintRecorder recorder(context, layer()->size()); |
94 | 100 |
95 SkPaint paint; | 101 SkPaint paint; |
96 paint.setAlpha(255); | 102 paint.setAlpha(255); |
97 paint.setAntiAlias(true); | 103 paint.setAntiAlias(true); |
98 paint.setStrokeWidth(kBorderSize); | 104 paint.setStrokeWidth(kBorderSize); |
99 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); | 105 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); |
100 | 106 |
101 gfx::Rect rect(layer()->bounds().size()); | 107 gfx::Rect rect(layer()->bounds().size()); |
(...skipping 10 matching lines...) Expand all Loading... | |
112 base::Closure PrepareForLayerBoundsChange() override { | 118 base::Closure PrepareForLayerBoundsChange() override { |
113 return base::Closure(); | 119 return base::Closure(); |
114 } | 120 } |
115 | 121 |
116 ui::Layer layer_; | 122 ui::Layer layer_; |
117 bool stroke_; | 123 bool stroke_; |
118 | 124 |
119 DISALLOW_COPY_AND_ASSIGN(ContentMask); | 125 DISALLOW_COPY_AND_ASSIGN(ContentMask); |
120 }; | 126 }; |
121 | 127 |
128 // The border renderer draws the border as well as outline on both the outer and | |
129 // inner radius to increase visibility. | |
130 class PartialMagnificationController::BorderRenderer | |
131 : public ui::LayerDelegate { | |
132 public: | |
133 explicit BorderRenderer(const gfx::Rect& bounds) | |
James Cook
2016/09/14 20:54:00
nit: |bounds| -> |magnifier_bounds|
sammiequon
2016/09/14 21:53:51
Done.
| |
134 : magnifier_bounds_(bounds) {} | |
135 | |
136 ~BorderRenderer() override {} | |
137 | |
138 private: | |
139 // ui::LayerDelegate: | |
140 void OnPaintLayer(const ui::PaintContext& context) override { | |
141 ui::PaintRecorder recorder(context, magnifier_bounds_.size()); | |
142 | |
143 SkPaint paint; | |
144 paint.setAntiAlias(true); | |
145 paint.setStyle(SkPaint::kStroke_Style); | |
146 | |
147 const int magnifier_radius = magnifier_bounds_.width() / 2; | |
148 // Draw the inner border. | |
149 paint.setStrokeWidth(kBorderSize); | |
150 paint.setColor(kBorderColor); | |
151 recorder.canvas()->DrawCircle(magnifier_bounds_.CenterPoint(), | |
152 magnifier_radius - kBorderSize / 2, paint); | |
153 | |
154 // Draw border outer outline and then draw the border inner outline. | |
155 paint.setStrokeWidth(kBorderOutlineThickness); | |
156 paint.setColor(kBorderOutlineColor); | |
157 recorder.canvas()->DrawCircle( | |
158 magnifier_bounds_.CenterPoint(), | |
159 magnifier_radius - kBorderOutlineThickness / 2, paint); | |
160 recorder.canvas()->DrawCircle( | |
161 magnifier_bounds_.CenterPoint(), | |
162 magnifier_radius - kBorderSize + kBorderOutlineThickness / 2, paint); | |
163 } | |
164 | |
165 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | |
166 | |
167 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | |
168 | |
169 base::Closure PrepareForLayerBoundsChange() override { | |
170 return base::Closure(); | |
171 } | |
172 | |
173 gfx::Rect magnifier_bounds_; | |
174 | |
175 DISALLOW_COPY_AND_ASSIGN(BorderRenderer); | |
176 }; | |
177 | |
122 PartialMagnificationController::PartialMagnificationController() { | 178 PartialMagnificationController::PartialMagnificationController() { |
123 Shell::GetInstance()->AddPreTargetHandler(this); | 179 Shell::GetInstance()->AddPreTargetHandler(this); |
124 } | 180 } |
125 | 181 |
126 PartialMagnificationController::~PartialMagnificationController() { | 182 PartialMagnificationController::~PartialMagnificationController() { |
127 CloseMagnifierWindow(); | 183 CloseMagnifierWindow(); |
128 | 184 |
129 Shell::GetInstance()->RemovePreTargetHandler(this); | 185 Shell::GetInstance()->RemovePreTargetHandler(this); |
130 } | 186 } |
131 | 187 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 aura::Window* window = host_widget_->GetNativeView(); | 311 aura::Window* window = host_widget_->GetNativeView(); |
256 window->SetName(kPartialMagniferWindowName); | 312 window->SetName(kPartialMagniferWindowName); |
257 | 313 |
258 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); | 314 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); |
259 | 315 |
260 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); | 316 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); |
261 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); | 317 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); |
262 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); | 318 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); |
263 root_layer->Add(zoom_layer_.get()); | 319 root_layer->Add(zoom_layer_.get()); |
264 | 320 |
265 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); | 321 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_TEXTURED)); |
266 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); | 322 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); |
267 border_layer_->SetColor(SK_ColorWHITE); | 323 border_layer_->set_delegate(new BorderRenderer(gfx::Rect(GetWindowSize()))); |
268 root_layer->Add(border_layer_.get()); | 324 root_layer->Add(border_layer_.get()); |
269 | 325 |
270 border_mask_.reset(new ContentMask(true, GetWindowSize())); | 326 border_mask_.reset(new ContentMask(true, GetWindowSize())); |
271 border_layer_->SetMaskLayer(border_mask_->layer()); | 327 border_layer_->SetMaskLayer(border_mask_->layer()); |
272 | 328 |
273 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); | 329 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); |
274 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); | 330 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); |
275 | 331 |
276 host_widget_->AddObserver(this); | 332 host_widget_->AddObserver(this); |
277 } | 333 } |
278 | 334 |
279 void PartialMagnificationController::CloseMagnifierWindow() { | 335 void PartialMagnificationController::CloseMagnifierWindow() { |
280 if (host_widget_) { | 336 if (host_widget_) { |
281 RemoveZoomWidgetObservers(); | 337 RemoveZoomWidgetObservers(); |
282 host_widget_->Close(); | 338 host_widget_->Close(); |
283 host_widget_ = nullptr; | 339 host_widget_ = nullptr; |
284 } | 340 } |
285 } | 341 } |
286 | 342 |
287 void PartialMagnificationController::RemoveZoomWidgetObservers() { | 343 void PartialMagnificationController::RemoveZoomWidgetObservers() { |
288 DCHECK(host_widget_); | 344 DCHECK(host_widget_); |
289 host_widget_->RemoveObserver(this); | 345 host_widget_->RemoveObserver(this); |
290 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); | 346 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); |
291 DCHECK(root_window); | 347 DCHECK(root_window); |
292 root_window->RemoveObserver(this); | 348 root_window->RemoveObserver(this); |
293 } | 349 } |
294 | 350 |
295 } // namespace ash | 351 } // namespace ash |
OLD | NEW |