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 magnifiying glass border in DIP. | |
James Cook
2016/09/14 03:04:58
nit: magnifying
sammiequon
2016/09/14 18:02:22
Done.
| |
31 const int kBorderOutlineThickness = 2; | |
32 const SkColor kBorderColor = SK_ColorWHITE; | |
James Cook
2016/09/14 03:04:59
nit: document what this looks like (is it black /
sammiequon
2016/09/14 18:02:22
Done.
| |
33 const SkColor kBorderOutlineColor = SK_ColorBLACK; | |
30 // Inset on the zoom filter. | 34 // Inset on the zoom filter. |
31 const int kZoomInset = 0; | 35 const int kZoomInset = 0; |
32 // Vertical offset between the center of the magnifier and the tip of the | 36 // 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 | 37 // pointer. TODO(jdufault): The vertical offset should only apply to the window |
34 // location, not the magnified contents. See crbug.com/637617. | 38 // location, not the magnified contents. See crbug.com/637617. |
35 const int kVerticalOffset = 0; | 39 const int kVerticalOffset = 0; |
36 | 40 |
37 // Name of the magnifier window. | 41 // Name of the magnifier window. |
38 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; | 42 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; |
39 | 43 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 layer_.set_delegate(this); | 85 layer_.set_delegate(this); |
82 layer_.SetFillsBoundsOpaquely(false); | 86 layer_.SetFillsBoundsOpaquely(false); |
83 layer_.SetBounds(gfx::Rect(mask_bounds)); | 87 layer_.SetBounds(gfx::Rect(mask_bounds)); |
84 } | 88 } |
85 | 89 |
86 ~ContentMask() override { layer_.set_delegate(nullptr); } | 90 ~ContentMask() override { layer_.set_delegate(nullptr); } |
87 | 91 |
88 ui::Layer* layer() { return &layer_; } | 92 ui::Layer* layer() { return &layer_; } |
89 | 93 |
90 private: | 94 private: |
91 // Overridden from LayerDelegate. | 95 // ui::LayerDelegate. |
92 void OnPaintLayer(const ui::PaintContext& context) override { | 96 void OnPaintLayer(const ui::PaintContext& context) override { |
93 ui::PaintRecorder recorder(context, layer()->size()); | 97 ui::PaintRecorder recorder(context, layer()->size()); |
94 | 98 |
95 SkPaint paint; | 99 SkPaint paint; |
96 paint.setAlpha(255); | 100 paint.setAlpha(255); |
97 paint.setAntiAlias(true); | 101 paint.setAntiAlias(true); |
98 paint.setStrokeWidth(kBorderSize); | 102 paint.setStrokeWidth(kBorderSize); |
99 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); | 103 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); |
100 | 104 |
101 gfx::Rect rect(layer()->bounds().size()); | 105 gfx::Rect rect(layer()->bounds().size()); |
(...skipping 10 matching lines...) Expand all Loading... | |
112 base::Closure PrepareForLayerBoundsChange() override { | 116 base::Closure PrepareForLayerBoundsChange() override { |
113 return base::Closure(); | 117 return base::Closure(); |
114 } | 118 } |
115 | 119 |
116 ui::Layer layer_; | 120 ui::Layer layer_; |
117 bool stroke_; | 121 bool stroke_; |
118 | 122 |
119 DISALLOW_COPY_AND_ASSIGN(ContentMask); | 123 DISALLOW_COPY_AND_ASSIGN(ContentMask); |
120 }; | 124 }; |
121 | 125 |
126 // The border render draws the border as well as outline on both the outer and | |
James Cook
2016/09/14 03:04:58
nit: render -> renderer
sammiequon
2016/09/14 18:02:23
Done.
| |
127 // inner radius to increase visibility. | |
128 class PartialMagnificationController::BorderRenderer | |
James Cook
2016/09/14 03:04:59
I like how you put this in an inner class.
sammiequon
2016/09/14 18:02:22
:)
| |
129 : public ui::LayerDelegate { | |
130 public: | |
131 explicit BorderRenderer(const gfx::Rect& bounds) : bounds_(bounds) {} | |
132 | |
133 ~BorderRenderer() override {} | |
134 | |
135 private: | |
136 // ui::LayerDelegate. | |
James Cook
2016/09/14 03:04:59
super nit: We usually end with a colon, like "ui::
sammiequon
2016/09/14 18:02:23
Done.
| |
137 void OnPaintLayer(const ui::PaintContext& context) override { | |
138 ui::PaintRecorder recorder(context, bounds_.size()); | |
139 | |
140 SkPaint paint; | |
141 paint.setAntiAlias(true); | |
142 paint.setStyle(SkPaint::kStroke_Style); | |
143 | |
144 // Draw the inner border. | |
145 paint.setStrokeWidth(kBorderSize); | |
146 paint.setColor(kBorderColor); | |
147 recorder.canvas()->DrawCircle(bounds_.CenterPoint(), | |
148 bounds_.width() / 2 - kBorderSize / 2, paint); | |
James Cook
2016/09/14 03:04:59
optional: I wonder if caching "const int radius =
sammiequon
2016/09/14 18:02:23
Done.
| |
149 | |
150 // Draw border outer outline and then draw the border inner outline. | |
151 paint.setStrokeWidth(kBorderOutlineThickness); | |
152 paint.setColor(kBorderOutlineColor); | |
153 recorder.canvas()->DrawCircle( | |
154 bounds_.CenterPoint(), | |
155 bounds_.width() / 2 - kBorderOutlineThickness / 2, paint); | |
156 recorder.canvas()->DrawCircle( | |
157 bounds_.CenterPoint(), | |
158 bounds_.width() / 2 - kBorderSize + kBorderOutlineThickness / 2, paint); | |
159 } | |
160 | |
161 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | |
162 | |
163 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | |
164 | |
165 base::Closure PrepareForLayerBoundsChange() override { | |
166 return base::Closure(); | |
167 } | |
168 | |
169 gfx::Rect bounds_; | |
James Cook
2016/09/14 03:04:59
document: bounds of what? or rename to something l
sammiequon
2016/09/14 18:02:23
Done.
| |
170 | |
171 DISALLOW_COPY_AND_ASSIGN(BorderRenderer); | |
172 }; | |
173 | |
122 PartialMagnificationController::PartialMagnificationController() { | 174 PartialMagnificationController::PartialMagnificationController() { |
123 Shell::GetInstance()->AddPreTargetHandler(this); | 175 Shell::GetInstance()->AddPreTargetHandler(this); |
124 } | 176 } |
125 | 177 |
126 PartialMagnificationController::~PartialMagnificationController() { | 178 PartialMagnificationController::~PartialMagnificationController() { |
127 CloseMagnifierWindow(); | 179 CloseMagnifierWindow(); |
128 | 180 |
129 Shell::GetInstance()->RemovePreTargetHandler(this); | 181 Shell::GetInstance()->RemovePreTargetHandler(this); |
130 } | 182 } |
131 | 183 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 aura::Window* window = host_widget_->GetNativeView(); | 307 aura::Window* window = host_widget_->GetNativeView(); |
256 window->SetName(kPartialMagniferWindowName); | 308 window->SetName(kPartialMagniferWindowName); |
257 | 309 |
258 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); | 310 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); |
259 | 311 |
260 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); | 312 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); |
261 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); | 313 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); |
262 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); | 314 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); |
263 root_layer->Add(zoom_layer_.get()); | 315 root_layer->Add(zoom_layer_.get()); |
264 | 316 |
265 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); | 317 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_TEXTURED)); |
266 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); | 318 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); |
267 border_layer_->SetColor(SK_ColorWHITE); | 319 border_layer_->set_delegate(new BorderRenderer(gfx::Rect(GetWindowSize()))); |
268 root_layer->Add(border_layer_.get()); | 320 root_layer->Add(border_layer_.get()); |
269 | 321 |
270 border_mask_.reset(new ContentMask(true, GetWindowSize())); | 322 border_mask_.reset(new ContentMask(true, GetWindowSize())); |
271 border_layer_->SetMaskLayer(border_mask_->layer()); | 323 border_layer_->SetMaskLayer(border_mask_->layer()); |
272 | 324 |
273 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); | 325 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); |
274 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); | 326 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); |
275 | 327 |
276 host_widget_->AddObserver(this); | 328 host_widget_->AddObserver(this); |
277 } | 329 } |
278 | 330 |
279 void PartialMagnificationController::CloseMagnifierWindow() { | 331 void PartialMagnificationController::CloseMagnifierWindow() { |
280 if (host_widget_) { | 332 if (host_widget_) { |
281 RemoveZoomWidgetObservers(); | 333 RemoveZoomWidgetObservers(); |
282 host_widget_->Close(); | 334 host_widget_->Close(); |
283 host_widget_ = nullptr; | 335 host_widget_ = nullptr; |
284 } | 336 } |
285 } | 337 } |
286 | 338 |
287 void PartialMagnificationController::RemoveZoomWidgetObservers() { | 339 void PartialMagnificationController::RemoveZoomWidgetObservers() { |
288 DCHECK(host_widget_); | 340 DCHECK(host_widget_); |
289 host_widget_->RemoveObserver(this); | 341 host_widget_->RemoveObserver(this); |
290 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); | 342 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); |
291 DCHECK(root_window); | 343 DCHECK(root_window); |
292 root_window->RemoveObserver(this); | 344 root_window->RemoveObserver(this); |
293 } | 345 } |
294 | 346 |
295 } // namespace ash | 347 } // namespace ash |
OLD | NEW |