Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | |
| 32 const SkColor kActiveTitleTextDefaultColor = SK_ColorBLACK; | |
| 33 const SkColor kInactiveTitleTextDefaultColor = 0x80888888; | |
|
dcheng
2012/04/27 01:18:39
Consider using SkColorSetARGB. It makes it clear w
jianli
2012/04/27 20:22:34
Done.
| |
| 34 const SkColor kAttentionTitleTextDefaultColor = SK_ColorWHITE; | |
| 35 | |
| 36 // Alpha value used in drawing inactive titlebar under non-default theme. | |
| 37 const U8CPU kInactiveAlphaBlending = 0x80; | |
| 38 | |
| 39 SkColor BlendSkColorWithAlpha(SkColor fg_color, SkColor bg_color, U8CPU alpha) { | |
| 40 if (alpha == 255) | |
| 41 return fg_color; | |
| 42 double fg_ratio = alpha / 255.0; | |
| 43 double bg_ratio = 1.0 - fg_ratio; | |
| 44 return SkColorSetRGB( | |
| 45 (SkColorGetR(fg_color) * fg_ratio + SkColorGetR(bg_color) * bg_ratio), | |
| 46 (SkColorGetG(fg_color) * fg_ratio + SkColorGetG(bg_color) * bg_ratio), | |
| 47 (SkColorGetB(fg_color) * fg_ratio + SkColorGetB(bg_color) * bg_ratio)); | |
| 48 } | |
| 49 | |
| 21 } // namespace | 50 } // namespace |
| 22 | 51 |
| 23 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk( | 52 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk( |
| 24 PanelBrowserWindowGtk* browser_window, GtkWindow* window) | 53 PanelBrowserWindowGtk* browser_window, GtkWindow* window) |
| 25 : BrowserTitlebar(browser_window, window), | 54 : BrowserTitlebar(browser_window, window), |
| 26 browser_window_(browser_window) { | 55 browser_window_(browser_window) { |
| 27 } | 56 } |
| 28 | 57 |
| 29 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() { | 58 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() { |
| 30 } | 59 } |
| 31 | 60 |
| 61 SkColor PanelBrowserTitlebarGtk::GetTitleColor() const { | |
| 62 if (browser_window_->IsDrawingAttention()) | |
|
jennb
2012/04/27 18:36:13
browser_window_->panel()->IsDrawingAttention()
jianli
2012/04/27 20:22:34
Changed to query about paint state, per discussion
| |
| 63 return kAttentionTitleTextDefaultColor; | |
| 64 | |
| 65 bool is_active = browser_window_->IsActive(); | |
| 66 if (theme_service()->UsingDefaultTheme()) { | |
| 67 return is_active ? kActiveTitleTextDefaultColor | |
| 68 : kInactiveTitleTextDefaultColor; | |
| 69 } else { | |
| 70 return is_active ? theme_service()->GetColor(ThemeService::COLOR_TAB_TEXT) : | |
| 71 BlendSkColorWithAlpha( | |
| 72 theme_service()->GetColor(ThemeService::COLOR_BACKGROUND_TAB_TEXT), | |
| 73 theme_service()->GetColor(ThemeService::COLOR_TOOLBAR), | |
| 74 kInactiveAlphaBlending); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void PanelBrowserTitlebarGtk::UpdateButtonBackground(CustomDrawButton* button) { | |
| 79 button->SetBackground(GetTitleColor(), NULL, NULL); | |
|
jennb
2012/04/27 18:36:13
The button's background is the same as the title t
jianli
2012/04/27 20:22:34
Changed per discussion.
| |
| 80 } | |
| 81 | |
| 82 void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() { | |
| 83 DCHECK(app_mode_title()); | |
| 84 | |
| 85 std::string title = | |
| 86 UTF16ToUTF8(browser_window_->browser()->GetWindowTitleForCurrentTab()); | |
| 87 | |
| 88 // Add the markup to show the title as bold. | |
| 89 gchar* escaped_title = g_markup_escape_text(title.c_str(), -1); | |
| 90 gchar* title_with_markup = g_strconcat(kTitleMarkupPrefix, | |
| 91 escaped_title, | |
| 92 kTitleMarkupSuffix, | |
| 93 NULL); | |
| 94 gtk_label_set_markup(GTK_LABEL(app_mode_title()), title_with_markup); | |
| 95 g_free(escaped_title); | |
| 96 g_free(title_with_markup); | |
| 97 } | |
| 98 | |
| 32 bool PanelBrowserTitlebarGtk::BuildButton(const std::string& button_token, | 99 bool PanelBrowserTitlebarGtk::BuildButton(const std::string& button_token, |
| 33 bool left_side) { | 100 bool left_side) { |
| 34 // Panel only shows close and minimize/restore buttons. | 101 // Panel only shows close and minimize/restore buttons. |
| 35 if (button_token != "close" && button_token != "minimize") | 102 if (button_token != "close" && button_token != "minimize") |
| 36 return false; | 103 return false; |
| 37 | 104 |
| 38 // Create unminimze button in order to show it to expand the minimized panel. | 105 // Create unminimze button in order to show it to expand the minimized panel. |
| 39 if (button_token == "minimize") | 106 if (button_token == "minimize") |
| 40 unminimize_button_.reset(CreateTitlebarButton("unminimize", left_side)); | 107 unminimize_button_.reset(CreateTitlebarButton("unminimize", left_side)); |
| 41 | 108 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 browser_window_->panel()->Close(); | 154 browser_window_->panel()->Close(); |
| 88 else if (minimize_button() && minimize_button()->widget() == button) | 155 else if (minimize_button() && minimize_button()->widget() == button) |
| 89 browser_window_->panel()->Minimize(); | 156 browser_window_->panel()->Minimize(); |
| 90 else if (unminimize_button_.get() && unminimize_button_->widget() == button) | 157 else if (unminimize_button_.get() && unminimize_button_->widget() == button) |
| 91 browser_window_->panel()->Restore(); | 158 browser_window_->panel()->Restore(); |
| 92 } | 159 } |
| 93 | 160 |
| 94 void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) { | 161 void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) { |
| 95 // Favicon menu is not supported in panels. | 162 // Favicon menu is not supported in panels. |
| 96 } | 163 } |
| 164 | |
| 165 void PanelBrowserTitlebarGtk::UpdateTextColor() { | |
| 166 DCHECK(app_mode_title()); | |
| 167 | |
| 168 GdkColor text_color = gfx::SkColorToGdkColor(GetTitleColor()); | |
| 169 gtk_util::SetLabelColor(app_mode_title(), &text_color); | |
| 170 } | |
| 171 | |
| 172 void PanelBrowserTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() { | |
| 173 if (!close_button()) | |
| 174 return; | |
| 175 | |
| 176 gint x; | |
| 177 gint y; | |
| 178 GtkAllocation widget_allocation = close_button()->WidgetAllocation(); | |
| 179 gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y); | |
| 180 | |
| 181 gfx::Rect button_rect(0, 0, widget_allocation.width, | |
| 182 widget_allocation.height); | |
| 183 if (!button_rect.Contains(x, y)) { | |
| 184 // Mouse is not over the close button. | |
| 185 return; | |
| 186 } | |
| 187 | |
| 188 // Create and emit an enter-notify-event on close button. | |
| 189 GValue return_value; | |
| 190 return_value.g_type = G_TYPE_BOOLEAN; | |
| 191 g_value_set_boolean(&return_value, false); | |
| 192 | |
| 193 GdkEvent* event = gdk_event_new(GDK_ENTER_NOTIFY); | |
| 194 event->crossing.window = | |
| 195 gtk_button_get_event_window(GTK_BUTTON(close_button()->widget())); | |
| 196 event->crossing.send_event = FALSE; | |
| 197 event->crossing.subwindow = gtk_widget_get_window(close_button()->widget()); | |
| 198 event->crossing.time = gtk_util::XTimeNow(); | |
| 199 event->crossing.x = x; | |
| 200 event->crossing.y = y; | |
| 201 event->crossing.x_root = widget_allocation.x; | |
| 202 event->crossing.y_root = widget_allocation.y; | |
| 203 event->crossing.mode = GDK_CROSSING_NORMAL; | |
| 204 event->crossing.detail = GDK_NOTIFY_ANCESTOR; | |
| 205 event->crossing.focus = true; | |
| 206 event->crossing.state = 0; | |
| 207 | |
| 208 g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()), | |
| 209 "enter-notify-event", event, | |
| 210 &return_value); | |
| 211 } | |
| OLD | NEW |