Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/browser/ui/libgtk2ui/gtk2_border.cc

Issue 131513005: linux_aura: Use GTK button borders in GTK theme mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/libgtk2ui/gtk2_border.h"
6
7 #include <gtk/gtk.h>
8
9 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image_skia_source.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/button/label_button.h"
msw 2014/01/21 19:18:19 nit: the button.h include should be sufficient; re
14 #include "ui/views/controls/button/label_button_border.h"
msw 2014/01/21 19:18:19 nit: the border.h include in the header should be
15
16 namespace libgtk2ui {
17
18 namespace {
19
20 int ViewsToGtkState(views::Button::ButtonState state) {
msw 2014/01/21 19:18:19 nit: should this return a GtkStateType?
21 switch (state) {
22 case views::Button::STATE_HOVERED:
23 return GTK_STATE_PRELIGHT;
24 case views::Button::STATE_PRESSED:
25 return GTK_STATE_ACTIVE;
26 default:
msw 2014/01/21 19:18:19 nit: handle Button::STATE_DISABLED / GTK_STATE_INS
27 return GTK_STATE_NORMAL;
28 }
29 }
30
31 class ButtonImageSkiaSource : public gfx::ImageSkiaSource {
32 public:
33 ButtonImageSkiaSource(const Gtk2UI* parent, int state, const gfx::Size& size)
34 : parent_(parent),
msw 2014/01/21 19:18:19 ditto nit: This isn't really the parent, should it
35 state_(state),
36 size_(size) {
37 }
38
39 virtual ~ButtonImageSkiaSource() {
40 }
41
42 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
43 int w = size_.width() * scale;
44 int h = size_.height() * scale;
45 return gfx::ImageSkiaRep(parent_->DrawGtkButtonBorder(state_, w, h), scale);
46 }
47
48 private:
49 const Gtk2UI* parent_;
50 int state_;
msw 2014/01/21 19:18:19 Should this be a GtkStateType?
51 gfx::Size size_;
52
53 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource);
54 };
55
56 } // namespace
57
58 Gtk2Border::Gtk2Border(Gtk2UI* parent,
59 views::View* owning_view,
60 views::LabelButtonBorder* label_button_border)
61 : parent_(parent),
62 use_gtk_(parent_->GetUseSystemTheme()),
63 owning_view_(owning_view),
64 label_button_border_(label_button_border) {
65 parent_->AddGtkBorder(this);
66 }
67
68 Gtk2Border::~Gtk2Border() {
69 parent_->RemoveGtkBorder(this);
70 }
71
72 void Gtk2Border::InvalidateAndSetUsesGtk(bool use_gtk) {
73 hovered_ = gfx::ImageSkia();
74 pressed_ = gfx::ImageSkia();
75
76 // Our owning view must have its layout invalidated because the insets could
77 // have changed.
78 owning_view_->InvalidateLayout();
79
80 use_gtk_ = use_gtk;
81 }
82
83 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) {
84 if (!use_gtk_) {
85 label_button_border_->Paint(view, canvas);
86 return;
87 }
88
89 int state = ViewsToGtkState(
msw 2014/01/21 19:18:19 nit: should this be a GtkStateType?
90 static_cast<const views::LabelButton&>(view).state());
msw 2014/01/21 19:18:19 nit: DCHECK_EQ(view, owning_view_), and use owning
91
92 if (state == GTK_STATE_PRELIGHT) {
93 if (hovered_.isNull() || hovered_.size() != view.size()) {
94 hovered_ = gfx::ImageSkia(
95 new ButtonImageSkiaSource(parent_, state, view.size()), view.size());
96 }
97
98 canvas->DrawImageInt(hovered_, 0, 0);
99 } else if (state == GTK_STATE_ACTIVE) {
100 if (pressed_.isNull() || pressed_.size() != view.size()) {
101 pressed_ = gfx::ImageSkia(
102 new ButtonImageSkiaSource(parent_, state, view.size()), view.size());
103 }
104
105 canvas->DrawImageInt(pressed_, 0, 0);
106 }
107 }
108
109 gfx::Insets Gtk2Border::GetInsets() const {
110 if (!use_gtk_)
111 return label_button_border_->GetInsets();
112
113 return parent_->GetButtonInsets();
114 }
115
116 gfx::Size Gtk2Border::GetMinimumSize() const {
117 if (!use_gtk_)
118 return label_button_border_->GetMinimumSize();
119
120 gfx::Insets insets = GetInsets();
121 return gfx::Size(insets.left() + insets.right(),
msw 2014/01/21 19:18:19 nit: use gfx::Insets::width() and height().
122 insets.top() + insets.bottom());
123 }
124
125 } // namespace libgtk2ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698