Commit da331ee4 authored by sammiequon's avatar sammiequon Committed by Commit bot

chromeos: Magnifier border is now more visible on light backgrounds.

Previously the partial magnifier border was difficult to see on white colored backgrounds. I add a textured layer instead of a solid color, so the border is outlined in black, so that it is visible on all backgrounds.

BUG=638996
TEST=none

https://screenshot.googleplex.com/htWDLX1Bxdp

Review-Url: https://codereview.chromium.org/2269383002
Cr-Commit-Position: refs/heads/master@{#418785}
parent 0ccb3fae
...@@ -27,6 +27,12 @@ const float kMagnificationScale = 2.f; ...@@ -27,6 +27,12 @@ const float kMagnificationScale = 2.f;
const int kMagnifierRadius = 200; const int kMagnifierRadius = 200;
// Size of the border around the magnifying glass in DIP. // Size of the border around the magnifying glass in DIP.
const int kBorderSize = 10; const int kBorderSize = 10;
// Thickness of the outline around magnifying glass border in DIP.
const int kBorderOutlineThickness = 2;
// The color of the border and its outlines. The border has an outline on both
// sides, producing a black/white/black ring.
const SkColor kBorderColor = SK_ColorWHITE;
const SkColor kBorderOutlineColor = SK_ColorBLACK;
// Inset on the zoom filter. // Inset on the zoom filter.
const int kZoomInset = 0; const int kZoomInset = 0;
// Vertical offset between the center of the magnifier and the tip of the // Vertical offset between the center of the magnifier and the tip of the
...@@ -88,7 +94,7 @@ class PartialMagnificationController::ContentMask : public ui::LayerDelegate { ...@@ -88,7 +94,7 @@ class PartialMagnificationController::ContentMask : public ui::LayerDelegate {
ui::Layer* layer() { return &layer_; } ui::Layer* layer() { return &layer_; }
private: private:
// Overridden from LayerDelegate. // ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override { void OnPaintLayer(const ui::PaintContext& context) override {
ui::PaintRecorder recorder(context, layer()->size()); ui::PaintRecorder recorder(context, layer()->size());
...@@ -119,6 +125,56 @@ class PartialMagnificationController::ContentMask : public ui::LayerDelegate { ...@@ -119,6 +125,56 @@ class PartialMagnificationController::ContentMask : public ui::LayerDelegate {
DISALLOW_COPY_AND_ASSIGN(ContentMask); DISALLOW_COPY_AND_ASSIGN(ContentMask);
}; };
// The border renderer draws the border as well as outline on both the outer and
// inner radius to increase visibility.
class PartialMagnificationController::BorderRenderer
: public ui::LayerDelegate {
public:
explicit BorderRenderer(const gfx::Rect& magnifier_bounds)
: magnifier_bounds_(magnifier_bounds) {}
~BorderRenderer() override {}
private:
// ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override {
ui::PaintRecorder recorder(context, magnifier_bounds_.size());
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
const int magnifier_radius = magnifier_bounds_.width() / 2;
// Draw the inner border.
paint.setStrokeWidth(kBorderSize);
paint.setColor(kBorderColor);
recorder.canvas()->DrawCircle(magnifier_bounds_.CenterPoint(),
magnifier_radius - kBorderSize / 2, paint);
// Draw border outer outline and then draw the border inner outline.
paint.setStrokeWidth(kBorderOutlineThickness);
paint.setColor(kBorderOutlineColor);
recorder.canvas()->DrawCircle(
magnifier_bounds_.CenterPoint(),
magnifier_radius - kBorderOutlineThickness / 2, paint);
recorder.canvas()->DrawCircle(
magnifier_bounds_.CenterPoint(),
magnifier_radius - kBorderSize + kBorderOutlineThickness / 2, paint);
}
void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
base::Closure PrepareForLayerBoundsChange() override {
return base::Closure();
}
gfx::Rect magnifier_bounds_;
DISALLOW_COPY_AND_ASSIGN(BorderRenderer);
};
PartialMagnificationController::PartialMagnificationController() { PartialMagnificationController::PartialMagnificationController() {
Shell::GetInstance()->AddPreTargetHandler(this); Shell::GetInstance()->AddPreTargetHandler(this);
} }
...@@ -262,9 +318,9 @@ void PartialMagnificationController::CreateMagnifierWindow( ...@@ -262,9 +318,9 @@ void PartialMagnificationController::CreateMagnifierWindow(
zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset); zoom_layer_->SetBackgroundZoom(kMagnificationScale, kZoomInset);
root_layer->Add(zoom_layer_.get()); root_layer->Add(zoom_layer_.get());
border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR)); border_layer_.reset(new ui::Layer(ui::LayerType::LAYER_TEXTURED));
border_layer_->SetBounds(gfx::Rect(GetWindowSize())); border_layer_->SetBounds(gfx::Rect(GetWindowSize()));
border_layer_->SetColor(SK_ColorWHITE); border_layer_->set_delegate(new BorderRenderer(gfx::Rect(GetWindowSize())));
root_layer->Add(border_layer_.get()); root_layer->Add(border_layer_.get());
border_mask_.reset(new ContentMask(true, GetWindowSize())); border_mask_.reset(new ContentMask(true, GetWindowSize()));
......
...@@ -47,6 +47,7 @@ class ASH_EXPORT PartialMagnificationController : public ui::EventHandler, ...@@ -47,6 +47,7 @@ class ASH_EXPORT PartialMagnificationController : public ui::EventHandler,
private: private:
friend class PartialMagnificationControllerTestApi; friend class PartialMagnificationControllerTestApi;
class BorderRenderer;
class ContentMask; class ContentMask;
// ui::EventHandler: // ui::EventHandler:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment