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

Side by Side Diff: chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc

Issue 10180011: Support painting panels with chromium themes on GTK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch to land Created 8 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h" 5 #include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h"
6 6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/gtk/custom_button.h" 9 #include "chrome/browser/ui/gtk/custom_button.h"
10 #include "chrome/browser/ui/gtk/gtk_util.h"
11 #include "chrome/browser/ui/gtk/theme_service_gtk.h"
8 #include "chrome/browser/ui/panels/panel.h" 12 #include "chrome/browser/ui/panels/panel.h"
9 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" 13 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h"
10 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
16 #include "ui/base/gtk/gtk_compat.h"
17 #include "ui/gfx/skia_utils_gtk.h"
12 18
13 namespace { 19 namespace {
14 20
15 // Spacing between buttons of panel's titlebar. 21 // Spacing between buttons of panel's titlebar.
16 const int kPanelButtonSpacing = 7; 22 const int kPanelButtonSpacing = 7;
17 23
18 // Spacing around outside of panel's titlebar buttons. 24 // Spacing around outside of panel's titlebar buttons.
19 const int kPanelButtonOuterPadding = 7; 25 const int kPanelButtonOuterPadding = 7;
20 26
27 // Markup for painting title as bold.
28 const char* const kTitleMarkupPrefix = "<span font_weight='bold'>";
29 const char* const kTitleMarkupSuffix = "</span>";
30
31 // Colors used to draw title in attention mode.
32 const SkColor kAttentionTitleTextDefaultColor = SK_ColorWHITE;
33
34 // Alpha value used in drawing inactive titlebar under non-default theme.
35 const U8CPU kInactiveAlphaBlending = 0x80;
36
37 SkColor BlendSkColorWithAlpha(SkColor fg_color, SkColor bg_color, U8CPU alpha) {
38 if (alpha == 255)
39 return fg_color;
40 double fg_ratio = alpha / 255.0;
41 double bg_ratio = 1.0 - fg_ratio;
42 return SkColorSetRGB(
43 (SkColorGetR(fg_color) * fg_ratio + SkColorGetR(bg_color) * bg_ratio),
44 (SkColorGetG(fg_color) * fg_ratio + SkColorGetG(bg_color) * bg_ratio),
45 (SkColorGetB(fg_color) * fg_ratio + SkColorGetB(bg_color) * bg_ratio));
46 }
47
21 } // namespace 48 } // namespace
22 49
23 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk( 50 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk(
24 PanelBrowserWindowGtk* browser_window, GtkWindow* window) 51 PanelBrowserWindowGtk* browser_window, GtkWindow* window)
25 : BrowserTitlebar(browser_window, window), 52 : BrowserTitlebar(browser_window, window),
26 browser_window_(browser_window) { 53 browser_window_(browser_window) {
27 } 54 }
28 55
29 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() { 56 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() {
30 } 57 }
31 58
59 SkColor PanelBrowserTitlebarGtk::GetTextColor() const {
60 PanelBrowserWindowGtk::PaintState paint_state =
61 browser_window_->GetPaintState();
62 if (paint_state == PanelBrowserWindowGtk::PAINT_FOR_ATTENTION)
63 return kAttentionTitleTextDefaultColor;
64
65 return paint_state == PanelBrowserWindowGtk::PAINT_AS_ACTIVE ?
66 theme_service()->GetColor(ThemeService::COLOR_TAB_TEXT) :
67 BlendSkColorWithAlpha(
68 theme_service()->GetColor(ThemeService::COLOR_BACKGROUND_TAB_TEXT),
69 theme_service()->GetColor(ThemeService::COLOR_TOOLBAR),
70 kInactiveAlphaBlending);
71 }
72
73 void PanelBrowserTitlebarGtk::UpdateButtonBackground(CustomDrawButton* button) {
74 // Don't need to update background since we're using transparent background.
75 }
76
77 void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() {
78 DCHECK(app_mode_title());
79
80 std::string title =
81 UTF16ToUTF8(browser_window_->browser()->GetWindowTitleForCurrentTab());
82
83 // Add the markup to show the title as bold.
84 gchar* escaped_title = g_markup_escape_text(title.c_str(), -1);
85 gchar* title_with_markup = g_strconcat(kTitleMarkupPrefix,
86 escaped_title,
87 kTitleMarkupSuffix,
88 NULL);
89 gtk_label_set_markup(GTK_LABEL(app_mode_title()), title_with_markup);
90 g_free(escaped_title);
91 g_free(title_with_markup);
92 }
93
32 bool PanelBrowserTitlebarGtk::BuildButton(const std::string& button_token, 94 bool PanelBrowserTitlebarGtk::BuildButton(const std::string& button_token,
33 bool left_side) { 95 bool left_side) {
34 // Panel only shows close and minimize/restore buttons. 96 // Panel only shows close and minimize/restore buttons.
35 if (button_token != "close" && button_token != "minimize") 97 if (button_token != "close" && button_token != "minimize")
36 return false; 98 return false;
37 99
38 // Create unminimze button in order to show it to expand the minimized panel. 100 // Create unminimze button in order to show it to expand the minimized panel.
39 if (button_token == "minimize") 101 if (button_token == "minimize")
40 unminimize_button_.reset(CreateTitlebarButton("unminimize", left_side)); 102 unminimize_button_.reset(CreateTitlebarButton("unminimize", left_side));
41 103
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 browser_window_->panel()->Close(); 149 browser_window_->panel()->Close();
88 else if (minimize_button() && minimize_button()->widget() == button) 150 else if (minimize_button() && minimize_button()->widget() == button)
89 browser_window_->panel()->Minimize(); 151 browser_window_->panel()->Minimize();
90 else if (unminimize_button_.get() && unminimize_button_->widget() == button) 152 else if (unminimize_button_.get() && unminimize_button_->widget() == button)
91 browser_window_->panel()->Restore(); 153 browser_window_->panel()->Restore();
92 } 154 }
93 155
94 void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) { 156 void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) {
95 // Favicon menu is not supported in panels. 157 // Favicon menu is not supported in panels.
96 } 158 }
159
160 void PanelBrowserTitlebarGtk::UpdateTextColor() {
161 DCHECK(app_mode_title());
162
163 GdkColor text_color = gfx::SkColorToGdkColor(GetTextColor());
164 gtk_util::SetLabelColor(app_mode_title(), &text_color);
165 }
166
167 void PanelBrowserTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() {
168 if (!close_button())
169 return;
170
171 gint x;
172 gint y;
173 GtkAllocation widget_allocation = close_button()->WidgetAllocation();
174 gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y);
175
176 gfx::Rect button_rect(0, 0, widget_allocation.width,
177 widget_allocation.height);
178 if (!button_rect.Contains(x, y)) {
179 // Mouse is not over the close button.
180 return;
181 }
182
183 // Create and emit an enter-notify-event on close button.
184 GValue return_value;
185 return_value.g_type = G_TYPE_BOOLEAN;
186 g_value_set_boolean(&return_value, false);
187
188 GdkEvent* event = gdk_event_new(GDK_ENTER_NOTIFY);
189 event->crossing.window =
190 gtk_button_get_event_window(GTK_BUTTON(close_button()->widget()));
191 event->crossing.send_event = FALSE;
192 event->crossing.subwindow = gtk_widget_get_window(close_button()->widget());
193 event->crossing.time = gtk_util::XTimeNow();
194 event->crossing.x = x;
195 event->crossing.y = y;
196 event->crossing.x_root = widget_allocation.x;
197 event->crossing.y_root = widget_allocation.y;
198 event->crossing.mode = GDK_CROSSING_NORMAL;
199 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
200 event->crossing.focus = true;
201 event->crossing.state = 0;
202
203 g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()),
204 "enter-notify-event", event,
205 &return_value);
206 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_titlebar_gtk.h ('k') | chrome/browser/ui/panels/panel_browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698