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" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/gtk/custom_button.h" | 9 #include "chrome/browser/ui/gtk/custom_button.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 11 #include "chrome/browser/ui/gtk/gtk_util.h" | 11 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 12 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | |
| 12 #include "chrome/browser/ui/panels/panel.h" | 13 #include "chrome/browser/ui/panels/panel.h" |
| 13 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" | 14 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | |
| 16 #include "content/public/browser/notification_service.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 14 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | |
| 16 #include "ui/base/gtk/gtk_compat.h" | 21 #include "ui/base/gtk/gtk_compat.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | |
| 23 #include "ui/base/resource/resource_bundle.h" | |
| 24 #include "ui/base/x/active_window_watcher_x.h" | |
| 17 #include "ui/gfx/skia_utils_gtk.h" | 25 #include "ui/gfx/skia_utils_gtk.h" |
| 18 | 26 |
| 19 namespace { | 27 namespace { |
| 20 | 28 |
| 29 // Padding around the titlebar. | |
| 30 const int kPanelTitlebarPaddingTop = 7; | |
| 31 const int kPanelTitlebarPaddingBottom = 7; | |
| 32 const int kPanelTitlebarPaddingLeft = 4; | |
| 33 const int kPanelTitlebarPaddingRight = 13; | |
| 34 | |
| 21 // Spacing between buttons of panel's titlebar. | 35 // Spacing between buttons of panel's titlebar. |
| 22 const int kPanelButtonSpacing = 7; | 36 const int kPanelButtonSpacing = 13; |
| 23 | 37 |
| 24 // Spacing around outside of panel's titlebar buttons. | 38 // Spacing between the icon and the title text. |
| 25 const int kPanelButtonOuterPadding = 7; | 39 const int kPanelIconTitleSpacing = 13; |
| 26 | 40 |
| 27 // Markup for painting title as bold. | 41 // Color used to draw title text under default theme. |
| 28 const char* const kTitleMarkupPrefix = "<span font_weight='bold'>"; | 42 const SkColor kTitleTextDefaultColor = SkColorSetRGB(0xf9, 0xf9, 0xf9); |
| 43 | |
| 44 // Markup used to paint the title with the desired font. | |
| 45 const char* const kTitleMarkupPrefix = "<span face='Arial' size='11264'>"; | |
| 29 const char* const kTitleMarkupSuffix = "</span>"; | 46 const char* const kTitleMarkupSuffix = "</span>"; |
| 30 | 47 |
| 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 | |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk( | 50 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk( |
| 51 PanelBrowserWindowGtk* browser_window, GtkWindow* window) | 51 PanelBrowserWindowGtk* browser_window, GtkWindow* window) |
| 52 : BrowserTitlebar(browser_window, window), | 52 : browser_window_(browser_window), |
| 53 browser_window_(browser_window) { | 53 window_(window), |
| 54 container_(NULL), | |
| 55 titlebar_right_buttons_vbox_(NULL), | |
| 56 titlebar_right_buttons_hbox_(NULL), | |
| 57 icon_(NULL), | |
| 58 title_(NULL), | |
| 59 window_has_focus_(false), | |
| 60 theme_service_(NULL) { | |
| 54 } | 61 } |
| 55 | 62 |
| 56 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() { | 63 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() { |
| 64 ui::ActiveWindowWatcherX::RemoveObserver(this); | |
| 65 } | |
| 66 | |
| 67 void PanelBrowserTitlebarGtk::Init() { | |
| 68 container_ = gtk_event_box_new(); | |
| 69 gtk_widget_set_name(container_, "chrome-panel-titlebar"); | |
| 70 gtk_event_box_set_visible_window(GTK_EVENT_BOX(container_), FALSE); | |
| 71 | |
| 72 // We use an alignment to control the titlebar paddings. | |
| 73 GtkWidget* container_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | |
| 74 gtk_container_add(GTK_CONTAINER(container_), container_alignment); | |
| 75 gtk_alignment_set_padding(GTK_ALIGNMENT(container_alignment), | |
| 76 kPanelTitlebarPaddingTop, | |
| 77 kPanelTitlebarPaddingBottom, | |
| 78 kPanelTitlebarPaddingLeft, | |
| 79 kPanelTitlebarPaddingRight); | |
| 80 | |
| 81 // Add a container box. | |
| 82 GtkWidget* container_hbox = gtk_hbox_new(FALSE, 0); | |
| 83 gtk_container_add(GTK_CONTAINER(container_alignment), container_hbox); | |
| 84 | |
| 85 g_signal_connect(window_, "window-state-event", | |
| 86 G_CALLBACK(OnWindowStateChangedThunk), this); | |
| 87 | |
| 88 // Add minimize/restore and close buttons. Panel buttons are always placed | |
| 89 // on the right part of the titlebar. | |
| 90 titlebar_right_buttons_vbox_ = gtk_vbox_new(FALSE, 0); | |
| 91 gtk_box_pack_end(GTK_BOX(container_hbox), titlebar_right_buttons_vbox_, | |
| 92 FALSE, FALSE, 0); | |
| 93 BuildButtons(); | |
| 94 | |
| 95 // Add hbox for holding icon and title. | |
| 96 GtkWidget* icon_title_hbox = gtk_hbox_new(FALSE, kPanelIconTitleSpacing); | |
| 97 gtk_box_pack_start(GTK_BOX(container_hbox), icon_title_hbox, TRUE, TRUE, 0); | |
| 98 | |
| 99 // Add icon. We use the app logo as a placeholder image so the title doesn't | |
| 100 // jump around. | |
| 101 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 102 icon_ = gtk_image_new_from_pixbuf(rb.GetNativeImageNamed( | |
| 103 IDR_PRODUCT_LOGO_16, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf()); | |
| 104 g_object_set_data(G_OBJECT(icon_), "left-align-popup", | |
| 105 reinterpret_cast<void*>(true)); | |
| 106 gtk_box_pack_start(GTK_BOX(icon_title_hbox), icon_, FALSE, FALSE, 0); | |
| 107 | |
| 108 // Add title. | |
| 109 title_ = gtk_label_new(NULL); | |
| 110 gtk_label_set_ellipsize(GTK_LABEL(title_), PANGO_ELLIPSIZE_END); | |
| 111 gtk_misc_set_alignment(GTK_MISC(title_), 0.0, 0.5); | |
| 112 gtk_box_pack_start(GTK_BOX(icon_title_hbox), title_, TRUE, TRUE, 0); | |
| 113 | |
| 114 UpdateTitleAndIcon(); | |
| 115 | |
| 116 theme_service_ = GtkThemeService::GetFrom( | |
| 117 browser_window_->browser()->profile()); | |
| 118 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | |
| 119 content::Source<ThemeService>(theme_service_)); | |
| 120 theme_service_->InitThemesFor(this); | |
| 121 | |
| 122 gtk_widget_show_all(container_); | |
| 123 | |
| 124 ui::ActiveWindowWatcherX::AddObserver(this); | |
| 57 } | 125 } |
| 58 | 126 |
| 59 SkColor PanelBrowserTitlebarGtk::GetTextColor() const { | 127 SkColor PanelBrowserTitlebarGtk::GetTextColor() const { |
| 60 PanelBrowserWindowGtk::PaintState paint_state = | 128 if (browser_window_->UsingDefaultTheme()) |
| 61 browser_window_->GetPaintState(); | 129 return kTitleTextDefaultColor; |
| 62 if (paint_state == PanelBrowserWindowGtk::PAINT_FOR_ATTENTION) | 130 return theme_service_->GetColor(browser_window_->paint_state() == |
| 63 return kAttentionTitleTextDefaultColor; | 131 PanelBrowserWindowGtk::PAINT_AS_ACTIVE ? |
| 64 | 132 ThemeService::COLOR_TAB_TEXT : |
| 65 return paint_state == PanelBrowserWindowGtk::PAINT_AS_ACTIVE ? | 133 ThemeService::COLOR_BACKGROUND_TAB_TEXT); |
| 66 theme_service()->GetColor(ThemeService::COLOR_TAB_TEXT) : | 134 } |
| 67 BlendSkColorWithAlpha( | 135 |
| 68 theme_service()->GetColor(ThemeService::COLOR_BACKGROUND_TAB_TEXT), | 136 void PanelBrowserTitlebarGtk::BuildButtons() { |
| 69 theme_service()->GetColor(ThemeService::COLOR_TOOLBAR), | 137 minimize_button_.reset(CreateButton(panel::MINIMIZE_BUTTON)); |
| 70 kInactiveAlphaBlending); | 138 restore_button_.reset(CreateButton(panel::RESTORE_BUTTON)); |
| 71 } | 139 close_button_.reset(CreateButton(panel::CLOSE_BUTTON)); |
| 72 | 140 |
| 73 void PanelBrowserTitlebarGtk::UpdateButtonBackground(CustomDrawButton* button) { | 141 // We control visibility of minimize and restore buttons. |
| 74 // Don't need to update background since we're using transparent background. | 142 gtk_widget_set_no_show_all(minimize_button_->widget(), TRUE); |
| 143 gtk_widget_set_no_show_all(restore_button_->widget(), TRUE); | |
| 144 | |
| 145 // Now show the correct widgets in the two hierarchies. | |
| 146 UpdateMinimizeRestoreButtonVisibility(); | |
| 147 } | |
| 148 | |
| 149 CustomDrawButton* PanelBrowserTitlebarGtk::CreateButton( | |
| 150 panel::TitlebarButtonType button_type) { | |
| 151 int normal_image_id; | |
| 152 int pressed_image_id; | |
| 153 int hover_image_id; | |
| 154 int tooltip_id; | |
| 155 GetButtonResources(button_type, &normal_image_id, &pressed_image_id, | |
| 156 &hover_image_id, &tooltip_id); | |
| 157 | |
| 158 CustomDrawButton* button = new CustomDrawButton(normal_image_id, | |
| 159 pressed_image_id, | |
| 160 hover_image_id, | |
| 161 0); | |
| 162 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK); | |
| 163 g_signal_connect(button->widget(), "clicked", | |
| 164 G_CALLBACK(OnButtonClickedThunk), this); | |
| 165 | |
| 166 std::string localized_tooltip = l10n_util::GetStringUTF8(tooltip_id); | |
| 167 gtk_widget_set_tooltip_text(button->widget(), | |
| 168 localized_tooltip.c_str()); | |
| 169 | |
| 170 GtkWidget* box = GetButtonHBox(); | |
| 171 gtk_box_pack_start(GTK_BOX(box), button->widget(), FALSE, FALSE, 0); | |
| 172 return button; | |
| 173 } | |
| 174 | |
| 175 void PanelBrowserTitlebarGtk::GetButtonResources( | |
| 176 panel::TitlebarButtonType button_type, | |
| 177 int* normal_image_id, | |
| 178 int* pressed_image_id, | |
| 179 int* hover_image_id, | |
| 180 int* tooltip_id) const { | |
| 181 switch (button_type) { | |
| 182 case panel::CLOSE_BUTTON: | |
| 183 *normal_image_id = IDR_PANEL_CLOSE; | |
| 184 *pressed_image_id = 0; | |
|
Dmitry Titov
2012/06/04 22:19:57
We do have pressed images ("_C")
jianli
2012/06/05 18:48:30
Done.
| |
| 185 *hover_image_id = IDR_PANEL_CLOSE_H; | |
| 186 *tooltip_id = IDS_PANEL_CLOSE_TOOLTIP; | |
| 187 break; | |
| 188 case panel::MINIMIZE_BUTTON: | |
| 189 *normal_image_id = IDR_PANEL_MINIMIZE; | |
| 190 *pressed_image_id = 0; | |
| 191 *hover_image_id = IDR_PANEL_MINIMIZE_H; | |
| 192 *tooltip_id = IDS_PANEL_MINIMIZE_TOOLTIP; | |
| 193 break; | |
| 194 case panel::RESTORE_BUTTON: | |
| 195 *normal_image_id = IDR_PANEL_RESTORE; | |
| 196 *pressed_image_id = 0; | |
| 197 *hover_image_id = IDR_PANEL_RESTORE_H; | |
| 198 *tooltip_id = IDS_PANEL_RESTORE_TOOLTIP; | |
| 199 break; | |
| 200 } | |
| 201 } | |
| 202 | |
| 203 GtkWidget* PanelBrowserTitlebarGtk::GetButtonHBox() { | |
| 204 if (!titlebar_right_buttons_hbox_) { | |
| 205 // We put the minimize/restore/close buttons in a vbox so they are top | |
| 206 // aligned (up to padding) and don't vertically stretch. | |
| 207 titlebar_right_buttons_hbox_ = gtk_hbox_new(FALSE, kPanelButtonSpacing); | |
| 208 gtk_box_pack_start(GTK_BOX(titlebar_right_buttons_vbox_), | |
| 209 titlebar_right_buttons_hbox_, FALSE, FALSE, 0); | |
| 210 } | |
| 211 | |
| 212 return titlebar_right_buttons_hbox_; | |
| 213 } | |
| 214 | |
| 215 void PanelBrowserTitlebarGtk::UpdateCustomFrame(bool use_custom_frame) { | |
| 216 UpdateMinimizeRestoreButtonVisibility(); | |
| 75 } | 217 } |
| 76 | 218 |
| 77 void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() { | 219 void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() { |
| 78 DCHECK(app_mode_title()); | 220 std::string title_text = |
| 79 | 221 UTF16ToUTF8(browser_window_->panel()->GetWindowTitle()); |
| 80 std::string title = UTF16ToUTF8(browser_window_->panel()->GetWindowTitle()); | 222 |
| 81 | 223 // Add the markup to show the title in the desired font. |
| 82 // Add the markup to show the title as bold. | 224 gchar* escaped_title_text = g_markup_escape_text(title_text.c_str(), -1); |
| 83 gchar* escaped_title = g_markup_escape_text(title.c_str(), -1); | 225 gchar* title_text_with_markup = g_strconcat(kTitleMarkupPrefix, |
| 84 gchar* title_with_markup = g_strconcat(kTitleMarkupPrefix, | 226 escaped_title_text, |
| 85 escaped_title, | 227 kTitleMarkupSuffix, |
| 86 kTitleMarkupSuffix, | 228 NULL); |
| 87 NULL); | 229 gtk_label_set_markup(GTK_LABEL(title_), title_text_with_markup); |
| 88 gtk_label_set_markup(GTK_LABEL(app_mode_title()), title_with_markup); | 230 g_free(escaped_title_text); |
| 89 g_free(escaped_title); | 231 g_free(title_text_with_markup); |
| 90 g_free(title_with_markup); | 232 } |
| 91 } | 233 |
| 92 | 234 void PanelBrowserTitlebarGtk::UpdateThrobber( |
| 93 bool PanelBrowserTitlebarGtk::BuildButton(const std::string& button_token, | 235 content::WebContents* web_contents) { |
| 94 bool left_side) { | 236 if (web_contents && web_contents->IsLoading()) { |
| 95 // Panel only shows close and minimize/restore buttons. | 237 GdkPixbuf* icon_pixbuf = |
| 96 if (button_token != "close" && button_token != "minimize") | 238 throbber_.GetNextFrame(web_contents->IsWaitingForResponse()); |
| 97 return false; | 239 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf); |
| 98 | 240 } else { |
| 99 if (!BrowserTitlebar::BuildButton(button_token, left_side)) | 241 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 100 return false; | 242 |
| 101 | 243 SkBitmap icon = browser_window_->browser()->GetCurrentPageIcon(); |
| 102 if (button_token == "minimize") { | 244 if (icon.empty()) { |
| 103 // Create unminimze button, used to expand the minimized panel. | 245 // Fallback to the Chromium icon if the page has no icon. |
| 104 unminimize_button_.reset(CreateTitlebarButton("unminimize", left_side)); | 246 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), |
| 105 | 247 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToGdkPixbuf()); |
| 106 // We control visibility of minimize and unminimize buttons. | 248 } else { |
| 107 gtk_widget_set_no_show_all(minimize_button()->widget(), TRUE); | 249 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon); |
| 108 gtk_widget_set_no_show_all(unminimize_button_->widget(), TRUE); | 250 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf); |
| 109 } | 251 g_object_unref(icon_pixbuf); |
| 110 return true; | 252 } |
| 111 } | 253 |
| 112 | 254 throbber_.Reset(); |
| 113 void PanelBrowserTitlebarGtk::GetButtonResources(const std::string& button_name, | 255 } |
| 114 int* normal_image_id, | 256 } |
| 115 int* pressed_image_id, | 257 |
| 116 int* hover_image_id, | 258 void PanelBrowserTitlebarGtk::ShowContextMenu(GdkEventButton* event) { |
| 117 int* tooltip_id) const { | 259 // Panel does not show any context menu. |
| 118 if (button_name == "close") { | 260 } |
| 119 *normal_image_id = IDR_PANEL_CLOSE; | 261 |
| 120 *pressed_image_id = 0; | 262 void PanelBrowserTitlebarGtk::UpdateTextColor() { |
| 121 *hover_image_id = IDR_PANEL_CLOSE_H; | 263 GdkColor text_color = gfx::SkColorToGdkColor(GetTextColor()); |
| 122 *tooltip_id = IDS_PANEL_CLOSE_TOOLTIP; | 264 gtk_util::SetLabelColor(title_, &text_color); |
| 123 } else if (button_name == "minimize") { | |
| 124 *normal_image_id = IDR_PANEL_MINIMIZE; | |
| 125 *pressed_image_id = 0; | |
| 126 *hover_image_id = IDR_PANEL_MINIMIZE_H; | |
| 127 *tooltip_id = IDS_PANEL_MINIMIZE_TOOLTIP; | |
| 128 } else if (button_name == "unminimize") { | |
| 129 *normal_image_id = IDR_PANEL_RESTORE; | |
| 130 *pressed_image_id = 0; | |
| 131 *hover_image_id = IDR_PANEL_RESTORE_H; | |
| 132 *tooltip_id = IDS_PANEL_RESTORE_TOOLTIP; | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 int PanelBrowserTitlebarGtk::GetButtonOuterPadding() const { | |
| 137 return kPanelButtonOuterPadding; | |
| 138 } | |
| 139 | |
| 140 int PanelBrowserTitlebarGtk::GetButtonSpacing() const { | |
| 141 return kPanelButtonSpacing; | |
| 142 } | 265 } |
| 143 | 266 |
| 144 void PanelBrowserTitlebarGtk::UpdateMinimizeRestoreButtonVisibility() { | 267 void PanelBrowserTitlebarGtk::UpdateMinimizeRestoreButtonVisibility() { |
| 145 if (!unminimize_button_.get() || !minimize_button()) | |
| 146 return; | |
| 147 | |
| 148 Panel* panel = browser_window_->panel(); | 268 Panel* panel = browser_window_->panel(); |
| 149 gtk_widget_set_visible(minimize_button()->widget(), panel->CanMinimize()); | 269 gtk_widget_set_visible(minimize_button_->widget(), panel->CanMinimize()); |
| 150 gtk_widget_set_visible(unminimize_button_->widget(), panel->CanRestore()); | 270 gtk_widget_set_visible(restore_button_->widget(), panel->CanRestore()); |
| 151 } | 271 } |
| 152 | 272 |
| 153 void PanelBrowserTitlebarGtk::HandleButtonClick(GtkWidget* button) { | 273 void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) { |
| 154 if (close_button() && close_button()->widget() == button) { | 274 // Favicon menu is not supported in panels. |
| 275 } | |
| 276 | |
| 277 gboolean PanelBrowserTitlebarGtk::OnWindowStateChanged(GtkWindow* window, | |
| 278 GdkEventWindowState* event) { | |
| 279 UpdateMinimizeRestoreButtonVisibility(); | |
| 280 UpdateTextColor(); | |
| 281 return FALSE; | |
| 282 } | |
| 283 | |
| 284 void PanelBrowserTitlebarGtk::OnButtonClicked(GtkWidget* button) { | |
| 285 if (close_button_->widget() == button) { | |
| 155 browser_window_->panel()->Close(); | 286 browser_window_->panel()->Close(); |
| 156 return; | 287 return; |
| 157 } | 288 } |
| 158 | 289 |
| 159 GdkEvent* event = gtk_get_current_event(); | 290 GdkEvent* event = gtk_get_current_event(); |
| 160 DCHECK(event && event->type == GDK_BUTTON_RELEASE); | 291 DCHECK(event && event->type == GDK_BUTTON_RELEASE); |
| 161 | 292 |
| 162 if (minimize_button() && minimize_button()->widget() == button) { | 293 if (minimize_button_->widget() == button) { |
| 163 browser_window_->panel()->OnMinimizeButtonClicked( | 294 browser_window_->panel()->OnMinimizeButtonClicked( |
| 164 (event->button.state & GDK_CONTROL_MASK) ? | 295 (event->button.state & GDK_CONTROL_MASK) ? |
| 165 panel::APPLY_TO_ALL : panel::NO_MODIFIER); | 296 panel::APPLY_TO_ALL : panel::NO_MODIFIER); |
| 166 } else if (unminimize_button_.get() && | 297 } else if (restore_button_->widget() == button) { |
| 167 unminimize_button_->widget() == button) { | |
| 168 browser_window_->panel()->OnRestoreButtonClicked( | 298 browser_window_->panel()->OnRestoreButtonClicked( |
| 169 (event->button.state & GDK_CONTROL_MASK) ? | 299 (event->button.state & GDK_CONTROL_MASK) ? |
| 170 panel::APPLY_TO_ALL : panel::NO_MODIFIER); | 300 panel::APPLY_TO_ALL : panel::NO_MODIFIER); |
| 171 } | 301 } |
| 172 | 302 |
| 173 gdk_event_free(event); | 303 gdk_event_free(event); |
| 174 } | 304 } |
| 175 | 305 |
| 176 void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) { | 306 void PanelBrowserTitlebarGtk::Observe( |
| 177 // Favicon menu is not supported in panels. | 307 int type, |
| 308 const content::NotificationSource& source, | |
| 309 const content::NotificationDetails& details) { | |
| 310 switch (type) { | |
| 311 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: | |
| 312 UpdateTextColor(); | |
| 313 break; | |
| 314 default: | |
| 315 NOTREACHED(); | |
| 316 } | |
| 178 } | 317 } |
| 179 | 318 |
| 180 void PanelBrowserTitlebarGtk::UpdateTextColor() { | 319 void PanelBrowserTitlebarGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| 181 DCHECK(app_mode_title()); | 320 // Can be called during shutdown; BrowserWindowGtk will set our |window_| |
| 321 // to NULL during that time. | |
| 322 if (!window_) | |
| 323 return; | |
| 182 | 324 |
| 183 GdkColor text_color = gfx::SkColorToGdkColor(GetTextColor()); | 325 window_has_focus_ = |
|
Dmitry Titov
2012/06/04 22:19:57
is window_has_focus_ used somewhere?
jianli
2012/06/05 18:48:30
Removed.
| |
| 184 gtk_util::SetLabelColor(app_mode_title(), &text_color); | 326 gtk_widget_get_window(GTK_WIDGET(window_)) == active_window; |
| 327 UpdateTextColor(); | |
| 185 } | 328 } |
| 186 | 329 |
| 187 void PanelBrowserTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() { | 330 void PanelBrowserTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() { |
| 188 if (!close_button()) | 331 if (!close_button()) |
| 189 return; | 332 return; |
| 190 | 333 |
| 191 gint x; | 334 gint x; |
| 192 gint y; | 335 gint y; |
| 193 GtkAllocation widget_allocation = close_button()->WidgetAllocation(); | 336 GtkAllocation widget_allocation = close_button()->WidgetAllocation(); |
| 194 gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y); | 337 gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 217 event->crossing.y_root = widget_allocation.y; | 360 event->crossing.y_root = widget_allocation.y; |
| 218 event->crossing.mode = GDK_CROSSING_NORMAL; | 361 event->crossing.mode = GDK_CROSSING_NORMAL; |
| 219 event->crossing.detail = GDK_NOTIFY_ANCESTOR; | 362 event->crossing.detail = GDK_NOTIFY_ANCESTOR; |
| 220 event->crossing.focus = true; | 363 event->crossing.focus = true; |
| 221 event->crossing.state = 0; | 364 event->crossing.state = 0; |
| 222 | 365 |
| 223 g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()), | 366 g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()), |
| 224 "enter-notify-event", event, | 367 "enter-notify-event", event, |
| 225 &return_value); | 368 &return_value); |
| 226 } | 369 } |
| 370 | |
| 371 GtkWidget* PanelBrowserTitlebarGtk::widget() const { | |
| 372 return container_; | |
| 373 } | |
| 374 | |
| 375 void PanelBrowserTitlebarGtk::set_window(GtkWindow* window) { | |
| 376 window_ = window; | |
| 377 } | |
| 378 | |
| 379 AvatarMenuButtonGtk* PanelBrowserTitlebarGtk::avatar_button() const { | |
| 380 // Not supported in panel. | |
| 381 return NULL; | |
| 382 } | |
| 383 | |
| OLD | NEW |