Index: chrome/browser/chromeos/ui/focus_ring_layer.cc |
diff --git a/chrome/browser/chromeos/ui/focus_ring_layer.cc b/chrome/browser/chromeos/ui/focus_ring_layer.cc |
index ab116b86c1cee0ccf9740a8d8eb6ae3a760247d7..43ba8364bb2d9c459ca49ec743400f474b6b7ae0 100644 |
--- a/chrome/browser/chromeos/ui/focus_ring_layer.cc |
+++ b/chrome/browser/chromeos/ui/focus_ring_layer.cc |
@@ -4,16 +4,10 @@ |
#include "chrome/browser/chromeos/ui/focus_ring_layer.h" |
-#include "ash/system/tray/actionable_view.h" |
-#include "ash/system/tray/tray_background_view.h" |
-#include "ash/system/tray/tray_popup_header_button.h" |
#include "base/bind.h" |
#include "ui/aura/window.h" |
#include "ui/compositor/layer.h" |
#include "ui/gfx/canvas.h" |
-#include "ui/views/controls/button/label_button.h" |
-#include "ui/views/view.h" |
-#include "ui/views/widget/widget.h" |
namespace chromeos { |
@@ -25,18 +19,17 @@ const SkColor kShadowColor = SkColorSetRGB(77, 144, 254); |
} // namespace |
-FocusRingLayer::FocusRingLayer() |
- : window_(NULL), |
+FocusRingLayerDelegate::~FocusRingLayerDelegate() {} |
+ |
+FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate) |
+ : delegate_(delegate), |
root_window_(NULL) { |
} |
FocusRingLayer::~FocusRingLayer() {} |
-void FocusRingLayer::Update() { |
- if (!window_) |
- return; |
- |
- aura::Window* root_window = window_->GetRootWindow(); |
+void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) { |
+ focus_ring_ = bounds; |
if (!layer_ || root_window != root_window_) { |
root_window_ = root_window; |
ui::Layer* root_layer = root_window->layer(); |
@@ -51,64 +44,18 @@ void FocusRingLayer::Update() { |
// since we created this layer. |
layer_->parent()->StackAtTop(layer_.get()); |
- // Translate native window coordinates to root window coordinates. |
- gfx::Point origin = focus_ring_.origin(); |
- aura::Window::ConvertPointToTarget(window_, root_window_, &origin); |
- gfx::Rect layer_bounds = focus_ring_; |
- layer_bounds.set_origin(origin); |
+ // Update the layer bounds. |
+ gfx::Rect layer_bounds = bounds; |
int inset = -(kShadowRadius + 2); |
layer_bounds.Inset(inset, inset, inset, inset); |
layer_->SetBounds(layer_bounds); |
} |
-void FocusRingLayer::SetForView(views::View* view) { |
- if (!view) { |
- if (layer_ && !focus_ring_.IsEmpty()) |
- layer_->SchedulePaint(focus_ring_); |
- focus_ring_ = gfx::Rect(); |
- return; |
- } |
- |
- DCHECK(view->GetWidget()); |
- window_ = view->GetWidget()->GetNativeWindow(); |
- |
- gfx::Rect view_bounds = view->GetContentsBounds(); |
- |
- // Workarounds that attempts to pick a better bounds. |
- if (view->GetClassName() == views::LabelButton::kViewClassName) { |
- view_bounds = view->GetLocalBounds(); |
- view_bounds.Inset(2, 2, 2, 2); |
- } |
- |
- // Workarounds for system tray items that have customized focus borders. The |
- // insets here must be consistent with the ones used by those classes. |
- if (view->GetClassName() == ash::ActionableView::kViewClassName) { |
- view_bounds = view->GetLocalBounds(); |
- view_bounds.Inset(1, 1, 3, 3); |
- } else if (view->GetClassName() == ash::TrayBackgroundView::kViewClassName) { |
- view_bounds.Inset(1, 1, 3, 3); |
- } else if (view->GetClassName() == |
- ash::TrayPopupHeaderButton::kViewClassName) { |
- view_bounds = view->GetLocalBounds(); |
- view_bounds.Inset(2, 1, 2, 2); |
- } |
- |
- focus_ring_ = view->ConvertRectToWidget(view_bounds); |
- Update(); |
-} |
- |
void FocusRingLayer::OnPaintLayer(gfx::Canvas* canvas) { |
- if (focus_ring_.IsEmpty()) |
+ if (!root_window_ || focus_ring_.IsEmpty()) |
return; |
- // Convert the focus ring from native-window-relative coordinates to |
- // layer-relative coordinates. |
- gfx::Point origin = focus_ring_.origin(); |
- aura::Window::ConvertPointToTarget(window_, root_window_, &origin); |
- origin -= layer_->bounds().OffsetFromOrigin(); |
- gfx::Rect bounds = focus_ring_; |
- bounds.set_origin(origin); |
- |
+ gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); |
SkPaint paint; |
paint.setColor(kShadowColor); |
paint.setFlags(SkPaint::kAntiAlias_Flag); |
@@ -129,7 +76,8 @@ void FocusRingLayer::OnDelegatedFrameDamage( |
} |
void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) { |
- Update(); |
+ if (delegate_) |
+ delegate_->OnDeviceScaleFactorChanged(); |
} |
base::Closure FocusRingLayer::PrepareForLayerBoundsChange() { |