Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: ash/magnifier/partial_magnification_controller.cc

Issue 2269383002: Magnifier border is now more visible on light backgrounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fixed patch set 3 errors. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 namespace ash { 17 namespace ash {
18 namespace { 18 namespace {
19 19
20 // Ratio of magnifier scale. 20 // Ratio of magnifier scale.
21 const float kMagnificationScale = 2.f; 21 const float kMagnificationScale = 2.f;
22 // Radius of the magnifying glass in DIP. 22 // Radius of the magnifying glass in DIP.
23 const int kMagnifierRadius = 200; 23 const int kMagnifierRadius = 200;
24 // Size of the border around the magnifying glass in DIP. 24 // Size of the border around the magnifying glass in DIP.
25 const int kBorderSize = 10; 25 const int kBorderSize = 10;
26 // Thickness of the outline around magnifiying glass border.
jdufault 2016/08/26 22:56:46 specify units (DIP)
sammiequon 2016/08/29 17:28:25 Done.
27 const int kBorderOutlineThickness = 2;
28 const SkColor kBorderColor = SK_ColorWHITE;
29 const SkColor kBorderOutlineColor = SK_ColorBLACK;
26 // Inset on the zoom filter. 30 // Inset on the zoom filter.
27 const int kZoomInset = 0; 31 const int kZoomInset = 0;
28 // Vertical offset between the center of the magnifier and the tip of the 32 // Vertical offset between the center of the magnifier and the tip of the
29 // pointer. TODO(jdufault): The vertical offset should only apply to the window 33 // pointer. TODO(jdufault): The vertical offset should only apply to the window
30 // location, not the magnified contents. See crbug.com/637617. 34 // location, not the magnified contents. See crbug.com/637617.
31 const int kVerticalOffset = 0; 35 const int kVerticalOffset = 0;
32 36
33 // Name of the magnifier window. 37 // Name of the magnifier window.
34 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; 38 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow";
35 39
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 layer_.set_delegate(this); 71 layer_.set_delegate(this);
68 layer_.SetFillsBoundsOpaquely(false); 72 layer_.SetFillsBoundsOpaquely(false);
69 layer_.SetBounds(gfx::Rect(mask_bounds)); 73 layer_.SetBounds(gfx::Rect(mask_bounds));
70 } 74 }
71 75
72 ~ContentMask() override { layer_.set_delegate(nullptr); } 76 ~ContentMask() override { layer_.set_delegate(nullptr); }
73 77
74 ui::Layer* layer() { return &layer_; } 78 ui::Layer* layer() { return &layer_; }
75 79
76 private: 80 private:
77 // Overridden from LayerDelegate. 81 // ui::LayerDelegate.
78 void OnPaintLayer(const ui::PaintContext& context) override { 82 void OnPaintLayer(const ui::PaintContext& context) override {
79 ui::PaintRecorder recorder(context, layer()->size()); 83 ui::PaintRecorder recorder(context, layer()->size());
80 84
81 SkPaint paint; 85 SkPaint paint;
82 paint.setAlpha(255); 86 paint.setAlpha(255);
83 paint.setAntiAlias(true); 87 paint.setAntiAlias(true);
84 paint.setStrokeWidth(kBorderSize); 88 paint.setStrokeWidth(kBorderSize);
85 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); 89 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
86 90
87 gfx::Rect rect(layer()->bounds().size()); 91 gfx::Rect rect(layer()->bounds().size());
(...skipping 10 matching lines...) Expand all
98 base::Closure PrepareForLayerBoundsChange() override { 102 base::Closure PrepareForLayerBoundsChange() override {
99 return base::Closure(); 103 return base::Closure();
100 } 104 }
101 105
102 ui::Layer layer_; 106 ui::Layer layer_;
103 bool stroke_; 107 bool stroke_;
104 108
105 DISALLOW_COPY_AND_ASSIGN(ContentMask); 109 DISALLOW_COPY_AND_ASSIGN(ContentMask);
106 }; 110 };
107 111
112 // The border render draws the border as well as outline on both the outer and
113 // inner radius to increase visibility.
114 class PartialMagnificationController::BorderRenderer
115 : public ui::LayerDelegate {
jdufault 2016/08/26 22:56:46 Is this from git cl format? Can you run it just in
sammiequon 2016/08/29 17:28:26 Yes, ran it again. It is 81 long if one line.
116 public:
117 BorderRenderer(const gfx::Rect& bounds) : bounds_(bounds) {}
118
119 ~BorderRenderer() override {}
120
121 private:
122 // ui::LayerDelegate.
123 void OnPaintLayer(const ui::PaintContext& context) override {
124 ui::PaintRecorder recorder(context, bounds_.size());
125
126 // Draw the border.
jdufault 2016/08/26 22:56:46 What about adding inner to make it more clear that
sammiequon 2016/08/29 17:28:26 Done.
127 SkPaint paint;
128 paint.setAntiAlias(true);
129 paint.setStrokeWidth(kBorderSize);
130 paint.setStyle(SkPaint::kStroke_Style);
jdufault 2016/08/26 22:56:46 Move all of the common paint config options away f
sammiequon 2016/08/29 17:28:25 Done.
131 paint.setColor(kBorderColor);
132 recorder.canvas()->DrawCircle(bounds_.CenterPoint(),
133 bounds_.width() / 2 - kBorderSize / 2, paint);
134
135 paint.setStrokeWidth(kBorderOutlineThickness);
136 paint.setColor(kBorderOutlineColor);
137 // Draw border outer outline.
jdufault 2016/08/26 22:56:46 What about moving these comments above setStrokeWi
sammiequon 2016/08/29 17:28:25 Done.
138 recorder.canvas()->DrawCircle(
139 bounds_.CenterPoint(),
140 bounds_.width() / 2 - kBorderOutlineThickness / 2, paint);
141 // Draw border inner outline.
142 recorder.canvas()->DrawCircle(
143 bounds_.CenterPoint(),
144 bounds_.width() / 2 - kBorderSize + kBorderOutlineThickness / 2, paint);
145 }
146
147 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
148
149 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
150
151 base::Closure PrepareForLayerBoundsChange() override {
152 return base::Closure();
153 }
154
155 gfx::Rect bounds_;
156
157 DISALLOW_COPY_AND_ASSIGN(BorderRenderer);
158 };
159
108 PartialMagnificationController::PartialMagnificationController() { 160 PartialMagnificationController::PartialMagnificationController() {
109 Shell::GetInstance()->AddPreTargetHandler(this); 161 Shell::GetInstance()->AddPreTargetHandler(this);
110 } 162 }
111 163
112 PartialMagnificationController::~PartialMagnificationController() { 164 PartialMagnificationController::~PartialMagnificationController() {
113 CloseMagnifierWindow(); 165 CloseMagnifierWindow();
114 166
115 Shell::GetInstance()->RemovePreTargetHandler(this); 167 Shell::GetInstance()->RemovePreTargetHandler(this);
116 } 168 }
117 169
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 aura::Window* window = host_widget_->GetNativeView(); 288 aura::Window* window = host_widget_->GetNativeView();
237 window->SetName(kPartialMagniferWindowName); 289 window->SetName(kPartialMagniferWindowName);
238 290
239 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); 291 ui::Layer* root_layer = host_widget_->GetNativeView()->layer();
240 292
241 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); 293 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR));
242 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); 294 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize()));
243 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); 295 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset);
244 root_layer->Add(zoom_layer_.get()); 296 root_layer->Add(zoom_layer_.get());
245 297
246 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); 298 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_TEXTURED));
247 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); 299 border_layer_->SetBounds(gfx::Rect(GetWindowSize()));
248 border_layer_->SetColor(SK_ColorWHITE); 300 border_layer_->set_delegate(new BorderRenderer(gfx::Rect(GetWindowSize())));
249 root_layer->Add(border_layer_.get()); 301 root_layer->Add(border_layer_.get());
250 302
251 border_mask_.reset(new ContentMask(true, GetWindowSize())); 303 border_mask_.reset(new ContentMask(true, GetWindowSize()));
252 border_layer_->SetMaskLayer(border_mask_->layer()); 304 border_layer_->SetMaskLayer(border_mask_->layer());
253 305
254 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); 306 zoom_mask_.reset(new ContentMask(false, GetWindowSize()));
255 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); 307 zoom_layer_->SetMaskLayer(zoom_mask_->layer());
256 308
257 host_widget_->AddObserver(this); 309 host_widget_->AddObserver(this);
258 } 310 }
259 311
260 void PartialMagnificationController::CloseMagnifierWindow() { 312 void PartialMagnificationController::CloseMagnifierWindow() {
261 if (host_widget_) { 313 if (host_widget_) {
262 RemoveZoomWidgetObservers(); 314 RemoveZoomWidgetObservers();
263 host_widget_->Close(); 315 host_widget_->Close();
264 host_widget_ = nullptr; 316 host_widget_ = nullptr;
265 } 317 }
266 } 318 }
267 319
268 void PartialMagnificationController::RemoveZoomWidgetObservers() { 320 void PartialMagnificationController::RemoveZoomWidgetObservers() {
269 DCHECK(host_widget_); 321 DCHECK(host_widget_);
270 host_widget_->RemoveObserver(this); 322 host_widget_->RemoveObserver(this);
271 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); 323 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow();
272 DCHECK(root_window); 324 DCHECK(root_window);
273 root_window->RemoveObserver(this); 325 root_window->RemoveObserver(this);
274 } 326 }
275 327
276 } // namespace ash 328 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698