summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/ui/focus_ring_layer.h
blob: 46b888c40408cbfba4061b0b7ed8ad73b0b54546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_LAYER_H_
#define CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_LAYER_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/gfx/rect.h"

namespace aura {
class Window;
}

namespace ui {
class Layer;
}

namespace chromeos {

// A delegate interface implemented by the object that owns a FocusRingLayer.
class FocusRingLayerDelegate {
 public:
  virtual void OnDeviceScaleFactorChanged() = 0;

 protected:
  virtual ~FocusRingLayerDelegate();
};

// FocusRingLayer draws a focus ring at a given global rectangle.
class FocusRingLayer : public ui::LayerDelegate {
 public:
  explicit FocusRingLayer(FocusRingLayerDelegate* delegate);
  virtual ~FocusRingLayer();

  // Move the focus ring layer to the given bounds in the coordinates of
  // the given root window.
  void Set(aura::Window* root_window, const gfx::Rect& bounds);

  ui::Layer* layer() { return layer_.get(); }
  aura::Window* root_window() { return root_window_; }

 protected:
  // Updates |root_window_| and creates |layer_| if it doesn't exist,
  // or if the root window has changed. Moves the layer to the top if
  // it wasn't there already.
  void CreateOrUpdateLayer(aura::Window* root_window, const char* layer_name);

 private:
  // ui::LayerDelegate overrides:
  virtual void OnPaintLayer(gfx::Canvas* canvas) override;
  virtual void OnDelegatedFrameDamage(
      const gfx::Rect& damage_rect_in_dip) override;
  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) override;
  virtual base::Closure PrepareForLayerBoundsChange() override;

  // The object that owns this layer.
  FocusRingLayerDelegate* delegate_;

  // The current root window containing the focused object.
  aura::Window* root_window_;

  // The current layer.
  scoped_ptr<ui::Layer> layer_;

  // The bounding rectangle of the focused object, in |root_window_|
  // coordinates.
  gfx::Rect focus_ring_;

  DISALLOW_COPY_AND_ASSIGN(FocusRingLayer);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_LAYER_H_