| 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/system/chromeos/palette/palette_utils.h" | 7 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "third_party/skia/include/core/SkDrawLooper.h" | 9 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 10 #include "ui/aura/window_event_dispatcher.h" | 10 #include "ui/aura/window_event_dispatcher.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 ~ContentMask() override { layer_.set_delegate(nullptr); } | 99 ~ContentMask() override { layer_.set_delegate(nullptr); } |
| 100 | 100 |
| 101 ui::Layer* layer() { return &layer_; } | 101 ui::Layer* layer() { return &layer_; } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 // ui::LayerDelegate: | 104 // ui::LayerDelegate: |
| 105 void OnPaintLayer(const ui::PaintContext& context) override { | 105 void OnPaintLayer(const ui::PaintContext& context) override { |
| 106 ui::PaintRecorder recorder(context, layer()->size()); | 106 ui::PaintRecorder recorder(context, layer()->size()); |
| 107 | 107 |
| 108 cc::PaintFlags paint; | 108 cc::PaintFlags flags; |
| 109 paint.setAlpha(255); | 109 flags.setAlpha(255); |
| 110 paint.setAntiAlias(true); | 110 flags.setAntiAlias(true); |
| 111 // Stroke is used for clipping the border which consists of the rendered | 111 // Stroke is used for clipping the border which consists of the rendered |
| 112 // border |kBorderSize| and the magnifier shadow |kShadowThickness| and | 112 // border |kBorderSize| and the magnifier shadow |kShadowThickness| and |
| 113 // |kShadowOffset|. | 113 // |kShadowOffset|. |
| 114 paint.setStrokeWidth(kBorderSize + kShadowThickness + kShadowOffset); | 114 flags.setStrokeWidth(kBorderSize + kShadowThickness + kShadowOffset); |
| 115 paint.setStyle(is_border_ ? cc::PaintFlags::kStroke_Style | 115 flags.setStyle(is_border_ ? cc::PaintFlags::kStroke_Style |
| 116 : cc::PaintFlags::kFill_Style); | 116 : cc::PaintFlags::kFill_Style); |
| 117 | 117 |
| 118 // If we want to clip the magnifier zone use the magnifiers radius. | 118 // If we want to clip the magnifier zone use the magnifiers radius. |
| 119 // Otherwise we want to clip the border, shadow and shadow offset so we | 119 // Otherwise we want to clip the border, shadow and shadow offset so we |
| 120 // start | 120 // start |
| 121 // at the halfway point of the stroke width. | 121 // at the halfway point of the stroke width. |
| 122 gfx::Rect rect(layer()->bounds().size()); | 122 gfx::Rect rect(layer()->bounds().size()); |
| 123 int clipping_radius = kMagnifierRadius; | 123 int clipping_radius = kMagnifierRadius; |
| 124 if (is_border_) | 124 if (is_border_) |
| 125 clipping_radius += (kShadowThickness + kShadowOffset + kBorderSize) / 2; | 125 clipping_radius += (kShadowThickness + kShadowOffset + kBorderSize) / 2; |
| 126 recorder.canvas()->DrawCircle(rect.CenterPoint(), clipping_radius, paint); | 126 recorder.canvas()->DrawCircle(rect.CenterPoint(), clipping_radius, flags); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 129 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
| 130 | 130 |
| 131 void OnDeviceScaleFactorChanged(float device_scale_factor) override { | 131 void OnDeviceScaleFactorChanged(float device_scale_factor) override { |
| 132 // Redrawing will take care of scale factor change. | 132 // Redrawing will take care of scale factor change. |
| 133 } | 133 } |
| 134 | 134 |
| 135 ui::Layer layer_; | 135 ui::Layer layer_; |
| 136 bool is_border_; | 136 bool is_border_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 ~BorderRenderer() override {} | 154 ~BorderRenderer() override {} |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 // ui::LayerDelegate: | 157 // ui::LayerDelegate: |
| 158 void OnPaintLayer(const ui::PaintContext& context) override { | 158 void OnPaintLayer(const ui::PaintContext& context) override { |
| 159 ui::PaintRecorder recorder(context, magnifier_window_bounds_.size()); | 159 ui::PaintRecorder recorder(context, magnifier_window_bounds_.size()); |
| 160 | 160 |
| 161 // Draw the shadow. | 161 // Draw the shadow. |
| 162 cc::PaintFlags shadow_paint; | 162 cc::PaintFlags shadow_flags; |
| 163 shadow_paint.setAntiAlias(true); | 163 shadow_flags.setAntiAlias(true); |
| 164 shadow_paint.setColor(SK_ColorTRANSPARENT); | 164 shadow_flags.setColor(SK_ColorTRANSPARENT); |
| 165 shadow_paint.setLooper( | 165 shadow_flags.setLooper( |
| 166 gfx::CreateShadowDrawLooperCorrectBlur(magnifier_shadows_)); | 166 gfx::CreateShadowDrawLooperCorrectBlur(magnifier_shadows_)); |
| 167 gfx::Rect shadow_bounds(magnifier_window_bounds_.size()); | 167 gfx::Rect shadow_bounds(magnifier_window_bounds_.size()); |
| 168 recorder.canvas()->DrawCircle( | 168 recorder.canvas()->DrawCircle( |
| 169 shadow_bounds.CenterPoint(), | 169 shadow_bounds.CenterPoint(), |
| 170 shadow_bounds.width() / 2 - kShadowThickness - kShadowOffset, | 170 shadow_bounds.width() / 2 - kShadowThickness - kShadowOffset, |
| 171 shadow_paint); | 171 shadow_flags); |
| 172 | 172 |
| 173 cc::PaintFlags border_paint; | 173 cc::PaintFlags border_flags; |
| 174 border_paint.setAntiAlias(true); | 174 border_flags.setAntiAlias(true); |
| 175 border_paint.setStyle(cc::PaintFlags::kStroke_Style); | 175 border_flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 176 | 176 |
| 177 // The radius of the magnifier and its border. | 177 // The radius of the magnifier and its border. |
| 178 const int magnifier_radius = kMagnifierRadius + kBorderSize; | 178 const int magnifier_radius = kMagnifierRadius + kBorderSize; |
| 179 | 179 |
| 180 // Draw the inner border. | 180 // Draw the inner border. |
| 181 border_paint.setStrokeWidth(kBorderSize); | 181 border_flags.setStrokeWidth(kBorderSize); |
| 182 border_paint.setColor(kBorderColor); | 182 border_flags.setColor(kBorderColor); |
| 183 recorder.canvas()->DrawCircle(magnifier_window_bounds_.CenterPoint(), | 183 recorder.canvas()->DrawCircle(magnifier_window_bounds_.CenterPoint(), |
| 184 magnifier_radius - kBorderSize / 2, | 184 magnifier_radius - kBorderSize / 2, |
| 185 border_paint); | 185 border_flags); |
| 186 | 186 |
| 187 // Draw border outer outline and then draw the border inner outline. | 187 // Draw border outer outline and then draw the border inner outline. |
| 188 border_paint.setStrokeWidth(kBorderOutlineThickness); | 188 border_flags.setStrokeWidth(kBorderOutlineThickness); |
| 189 border_paint.setColor(kBorderOutlineColor); | 189 border_flags.setColor(kBorderOutlineColor); |
| 190 recorder.canvas()->DrawCircle( | 190 recorder.canvas()->DrawCircle( |
| 191 magnifier_window_bounds_.CenterPoint(), | 191 magnifier_window_bounds_.CenterPoint(), |
| 192 magnifier_radius - kBorderOutlineThickness / 2, border_paint); | 192 magnifier_radius - kBorderOutlineThickness / 2, border_flags); |
| 193 recorder.canvas()->DrawCircle( | 193 recorder.canvas()->DrawCircle( |
| 194 magnifier_window_bounds_.CenterPoint(), | 194 magnifier_window_bounds_.CenterPoint(), |
| 195 magnifier_radius - kBorderSize + kBorderOutlineThickness / 2, | 195 magnifier_radius - kBorderSize + kBorderOutlineThickness / 2, |
| 196 border_paint); | 196 border_flags); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 199 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
| 200 | 200 |
| 201 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 201 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
| 202 | 202 |
| 203 gfx::Rect magnifier_window_bounds_; | 203 gfx::Rect magnifier_window_bounds_; |
| 204 std::vector<gfx::ShadowValue> magnifier_shadows_; | 204 std::vector<gfx::ShadowValue> magnifier_shadows_; |
| 205 | 205 |
| 206 DISALLOW_COPY_AND_ASSIGN(BorderRenderer); | 206 DISALLOW_COPY_AND_ASSIGN(BorderRenderer); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 373 |
| 374 void PartialMagnificationController::RemoveZoomWidgetObservers() { | 374 void PartialMagnificationController::RemoveZoomWidgetObservers() { |
| 375 DCHECK(host_widget_); | 375 DCHECK(host_widget_); |
| 376 host_widget_->RemoveObserver(this); | 376 host_widget_->RemoveObserver(this); |
| 377 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); | 377 aura::Window* root_window = host_widget_->GetNativeView()->GetRootWindow(); |
| 378 DCHECK(root_window); | 378 DCHECK(root_window); |
| 379 root_window->RemoveObserver(this); | 379 root_window->RemoveObserver(this); |
| 380 } | 380 } |
| 381 | 381 |
| 382 } // namespace ash | 382 } // namespace ash |
| OLD | NEW |