| 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 and its outlines. The border has an outline on both | |
| 33 // sides, producing a black/white/black ring. | |
| 34 const SkColor kBorderColor = SK_ColorWHITE; | |
| 35 const SkColor kBorderOutlineColor = SK_ColorBLACK; | |
| 36 // Inset on the zoom filter. | 30 // Inset on the zoom filter. |
| 37 const int kZoomInset = 0; | 31 const int kZoomInset = 0; |
| 38 // 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 |
| 39 // 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 |
| 40 // location, not the magnified contents. See crbug.com/637617. | 34 // location, not the magnified contents. See crbug.com/637617. |
| 41 const int kVerticalOffset = 0; | 35 const int kVerticalOffset = 0; |
| 42 | 36 |
| 43 // Name of the magnifier window. | 37 // Name of the magnifier window. |
| 44 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; | 38 const char kPartialMagniferWindowName[] = "PartialMagnifierWindow"; |
| 45 | 39 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 layer_.set_delegate(this); | 81 layer_.set_delegate(this); |
| 88 layer_.SetFillsBoundsOpaquely(false); | 82 layer_.SetFillsBoundsOpaquely(false); |
| 89 layer_.SetBounds(gfx::Rect(mask_bounds)); | 83 layer_.SetBounds(gfx::Rect(mask_bounds)); |
| 90 } | 84 } |
| 91 | 85 |
| 92 ~ContentMask() override { layer_.set_delegate(nullptr); } | 86 ~ContentMask() override { layer_.set_delegate(nullptr); } |
| 93 | 87 |
| 94 ui::Layer* layer() { return &layer_; } | 88 ui::Layer* layer() { return &layer_; } |
| 95 | 89 |
| 96 private: | 90 private: |
| 97 // ui::LayerDelegate: | 91 // Overridden from LayerDelegate. |
| 98 void OnPaintLayer(const ui::PaintContext& context) override { | 92 void OnPaintLayer(const ui::PaintContext& context) override { |
| 99 ui::PaintRecorder recorder(context, layer()->size()); | 93 ui::PaintRecorder recorder(context, layer()->size()); |
| 100 | 94 |
| 101 SkPaint paint; | 95 SkPaint paint; |
| 102 paint.setAlpha(255); | 96 paint.setAlpha(255); |
| 103 paint.setAntiAlias(true); | 97 paint.setAntiAlias(true); |
| 104 paint.setStrokeWidth(kBorderSize); | 98 paint.setStrokeWidth(kBorderSize); |
| 105 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); | 99 paint.setStyle(stroke_ ? SkPaint::kStroke_Style : SkPaint::kFill_Style); |
| 106 | 100 |
| 107 gfx::Rect rect(layer()->bounds().size()); | 101 gfx::Rect rect(layer()->bounds().size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 118 base::Closure PrepareForLayerBoundsChange() override { | 112 base::Closure PrepareForLayerBoundsChange() override { |
| 119 return base::Closure(); | 113 return base::Closure(); |
| 120 } | 114 } |
| 121 | 115 |
| 122 ui::Layer layer_; | 116 ui::Layer layer_; |
| 123 bool stroke_; | 117 bool stroke_; |
| 124 | 118 |
| 125 DISALLOW_COPY_AND_ASSIGN(ContentMask); | 119 DISALLOW_COPY_AND_ASSIGN(ContentMask); |
| 126 }; | 120 }; |
| 127 | 121 |
| 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& magnifier_bounds) | |
| 134 : magnifier_bounds_(magnifier_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 | |
| 178 PartialMagnificationController::PartialMagnificationController() { | 122 PartialMagnificationController::PartialMagnificationController() { |
| 179 Shell::GetInstance()->AddPreTargetHandler(this); | 123 Shell::GetInstance()->AddPreTargetHandler(this); |
| 180 } | 124 } |
| 181 | 125 |
| 182 PartialMagnificationController::~PartialMagnificationController() { | 126 PartialMagnificationController::~PartialMagnificationController() { |
| 183 CloseMagnifierWindow(); | 127 CloseMagnifierWindow(); |
| 184 | 128 |
| 185 Shell::GetInstance()->RemovePreTargetHandler(this); | 129 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 186 } | 130 } |
| 187 | 131 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 aura::Window* window = host_widget_->GetNativeView(); | 255 aura::Window* window = host_widget_->GetNativeView(); |
| 312 window->SetName(kPartialMagniferWindowName); | 256 window->SetName(kPartialMagniferWindowName); |
| 313 | 257 |
| 314 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); | 258 ui::Layer* root_layer = host_widget_->GetNativeView()->layer(); |
| 315 | 259 |
| 316 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); | 260 zoom_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); |
| 317 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); | 261 zoom_layer_->SetBounds(gfx::Rect(GetWindowSize())); |
| 318 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); | 262 zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); |
| 319 root_layer->Add(zoom_layer_.get()); | 263 root_layer->Add(zoom_layer_.get()); |
| 320 | 264 |
| 321 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_TEXTURED)); | 265 border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); |
| 322 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); | 266 border_layer_->SetBounds(gfx::Rect(GetWindowSize())); |
| 323 border_layer_->set_delegate(new BorderRenderer(gfx::Rect(GetWindowSize()))); | 267 border_layer_->SetColor(SK_ColorWHITE); |
| 324 root_layer->Add(border_layer_.get()); | 268 root_layer->Add(border_layer_.get()); |
| 325 | 269 |
| 326 border_mask_.reset(new ContentMask(true, GetWindowSize())); | 270 border_mask_.reset(new ContentMask(true, GetWindowSize())); |
| 327 border_layer_->SetMaskLayer(border_mask_->layer()); | 271 border_layer_->SetMaskLayer(border_mask_->layer()); |
| 328 | 272 |
| 329 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); | 273 zoom_mask_.reset(new ContentMask(false, GetWindowSize())); |
| 330 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); | 274 zoom_layer_->SetMaskLayer(zoom_mask_->layer()); |
| 331 | 275 |
| 332 host_widget_->AddObserver(this); | 276 host_widget_->AddObserver(this); |
| 333 } | 277 } |
| 334 | 278 |
| 335 void PartialMagnificationController::CloseMagnifierWindow() { | 279 void PartialMagnificationController::CloseMagnifierWindow() { |
| 336 if (host_widget_) { | 280 if (host_widget_) { |
| 337 RemoveZoomWidgetObservers(); | 281 RemoveZoomWidgetObservers(); |
| 338 host_widget_->Close(); | 282 host_widget_->Close(); |
| 339 host_widget_ = nullptr; | 283 host_widget_ = nullptr; |
| 340 } | 284 } |
| 341 } | 285 } |
| 342 | 286 |
| 343 void PartialMagnificationController::RemoveZoomWidgetObservers() { | 287 void PartialMagnificationController::RemoveZoomWidgetObservers() { |
| 344 DCHECK(host_widget_); | 288 DCHECK(host_widget_); |
| 345 host_widget_->RemoveObserver(this); | 289 host_widget_->RemoveObserver(this); |
| 346 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); | 290 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); |
| 347 DCHECK(root_window); | 291 DCHECK(root_window); |
| 348 root_window->RemoveObserver(this); | 292 root_window->RemoveObserver(this); |
| 349 } | 293 } |
| 350 | 294 |
| 351 } // namespace ash | 295 } // namespace ash |
| OLD | NEW |