summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/libgtk2ui/gtk2_border.h
blob: 10e6663fe0d577eaa76fdc9e74460dac57af50b2 (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
// Copyright 2014 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_UI_LIBGTK2UI_GTK2_BORDER_H_
#define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_

#include "base/scoped_observer.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/button.h"

namespace gfx {
class Canvas;
}

namespace views {
class LabelButton;
class Border;
}

namespace libgtk2ui {
class Gtk2UI;

// Draws a gtk button border, and manages the memory of the resulting pixbufs.
class Gtk2Border : public views::Border, public ui::NativeThemeObserver {
 public:
  Gtk2Border(Gtk2UI* gtk2_ui,
             views::LabelButton* owning_button);
  virtual ~Gtk2Border();

  // Overridden from views::Border:
  virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
  virtual gfx::Insets GetInsets() const OVERRIDE;
  virtual gfx::Size GetMinimumSize() const OVERRIDE;

  // Overridden from views::NativeThemeChangeObserver:
  virtual void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) OVERRIDE;

 private:
  void PaintState(const ui::NativeTheme::State state,
                  const ui::NativeTheme::ExtraParams& extra,
                  const gfx::Rect& rect,
                  gfx::Canvas* canvas);

  bool ShouldDrawBorder(bool focused, views::Button::ButtonState state);

  Gtk2UI* gtk2_ui_;

  gfx::ImageSkia button_images_[2][views::Button::STATE_COUNT];

  // The view to which we are a border. We keep track of this so that we can
  // force invalidate the layout on theme changes.
  views::LabelButton* owning_button_;

  ScopedObserver<ui::NativeTheme, ui::NativeThemeObserver> observer_manager_;

  DISALLOW_COPY_AND_ASSIGN(Gtk2Border);
};

}  // namespace libgtk2ui

#endif  // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_