| 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 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/ui/gtk/browser_titlebar.h" | 8 #include <gtk/gtk.h> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/ui/gtk/browser_titlebar_base.h" |
| 13 #include "chrome/browser/ui/gtk/titlebar_throb_animation.h" |
| 14 #include "chrome/browser/ui/panels/panel_constants.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "ui/base/gtk/gtk_signal.h" |
| 9 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
| 10 | 19 |
| 20 class CustomDrawButton; |
| 21 class GtkThemeService; |
| 11 class PanelBrowserWindowGtk; | 22 class PanelBrowserWindowGtk; |
| 12 | 23 |
| 13 class PanelBrowserTitlebarGtk : public BrowserTitlebar { | 24 namespace content { |
| 25 class WebContents; |
| 26 } |
| 27 |
| 28 class PanelBrowserTitlebarGtk : public BrowserTitlebarBase, |
| 29 public content::NotificationObserver { |
| 14 public: | 30 public: |
| 15 PanelBrowserTitlebarGtk(PanelBrowserWindowGtk* browser_window, | 31 PanelBrowserTitlebarGtk(PanelBrowserWindowGtk* browser_window, |
| 16 GtkWindow* window); | 32 GtkWindow* window); |
| 17 virtual ~PanelBrowserTitlebarGtk(); | 33 virtual ~PanelBrowserTitlebarGtk(); |
| 18 | 34 |
| 35 void UpdateTextColor(); |
| 19 void UpdateMinimizeRestoreButtonVisibility(); | 36 void UpdateMinimizeRestoreButtonVisibility(); |
| 20 | 37 |
| 21 // When a panel appears in the same position as the one of the panel being | 38 // When a panel appears in the same position as the one of the panel being |
| 22 // closed and the cursor stays in the close button, the close button appears | 39 // closed and the cursor stays in the close button, the close button appears |
| 23 // not to be clickable. This is because neither "enter-notify-event" nor | 40 // not to be clickable. This is because neither "enter-notify-event" nor |
| 24 // "clicked" event for the new panel gets fired if the mouse does not move. | 41 // "clicked" event for the new panel gets fired if the mouse does not move. |
| 25 // This creates a bad experience when a user has multiple panels of the same | 42 // This creates a bad experience when a user has multiple panels of the same |
| 26 // size (which is typical) and tries closing them all by repeatedly clicking | 43 // size (which is typical) and tries closing them all by repeatedly clicking |
| 27 // in the same place on the screen. | 44 // in the same place on the screen. |
| 28 // | 45 // |
| 29 // Opened a gtk bug for this - | 46 // Opened a gtk bug for this - |
| 30 // https://bugzilla.gnome.org/show_bug.cgi?id=667841 | 47 // https://bugzilla.gnome.org/show_bug.cgi?id=667841 |
| 31 void SendEnterNotifyToCloseButtonIfUnderMouse(); | 48 void SendEnterNotifyToCloseButtonIfUnderMouse(); |
| 32 | 49 |
| 33 // Overridden from BrowserTitlebar: | 50 // Overriden from BrowserTitlebarBase. |
| 34 virtual void UpdateButtonBackground(CustomDrawButton* button) OVERRIDE; | 51 virtual void Init() OVERRIDE; |
| 35 virtual void UpdateTitleAndIcon() OVERRIDE; | 52 virtual void UpdateTitleAndIcon() OVERRIDE; |
| 36 virtual void UpdateTextColor() OVERRIDE; | 53 virtual void UpdateCustomFrame(bool use_custom_frame) OVERRIDE; |
| 37 | 54 virtual void UpdateThrobber(content::WebContents* web_contents) OVERRIDE; |
| 38 protected: | 55 virtual void ShowContextMenu(GdkEventButton* event) OVERRIDE; |
| 39 // Overridden from BrowserTitlebar: | 56 virtual GtkWidget* widget() const OVERRIDE; |
| 40 virtual bool BuildButton(const std::string& button_token, | 57 virtual void set_window(GtkWindow* window) OVERRIDE; |
| 41 bool left_side) OVERRIDE; | 58 virtual AvatarMenuButtonGtk* avatar_button() const OVERRIDE; |
| 42 virtual void GetButtonResources(const std::string& button_name, | |
| 43 int* normal_image_id, | |
| 44 int* pressed_image_id, | |
| 45 int* hover_image_id, | |
| 46 int* tooltip_id) const OVERRIDE; | |
| 47 virtual int GetButtonOuterPadding() const OVERRIDE; | |
| 48 virtual int GetButtonSpacing() const OVERRIDE; | |
| 49 virtual void HandleButtonClick(GtkWidget* button) OVERRIDE; | |
| 50 virtual void ShowFaviconMenu(GdkEventButton* event) OVERRIDE; | |
| 51 | 59 |
| 52 private: | 60 private: |
| 53 friend class NativePanelTestingGtk; | 61 friend class NativePanelTestingGtk; |
| 54 | 62 |
| 55 CustomDrawButton* unminimize_button() const { | 63 // Overridden from content::NotificationObserver: |
| 56 return unminimize_button_.get(); | 64 virtual void Observe(int type, |
| 57 } | 65 const content::NotificationSource& source, |
| 66 const content::NotificationDetails& details) OVERRIDE; |
| 67 |
| 68 void BuildButtons(); |
| 69 CustomDrawButton* CreateButton(panel::TitlebarButtonType button_type); |
| 70 void GetButtonResources(panel::TitlebarButtonType button_type, |
| 71 int* normal_image_id, |
| 72 int* pressed_image_id, |
| 73 int* hover_image_id, |
| 74 int* tooltip_id) const; |
| 75 GtkWidget* GetButtonHBox(); |
| 76 |
| 77 // Callback for changes to window state. This includes minimizing/restoring |
| 78 // the window. |
| 79 CHROMEG_CALLBACK_1(PanelBrowserTitlebarGtk, gboolean, OnWindowStateChanged, |
| 80 GtkWindow*, GdkEventWindowState*); |
| 81 |
| 82 // Callback for minimize/restore/close buttons. |
| 83 CHROMEGTK_CALLBACK_0(PanelBrowserTitlebarGtk, void, OnButtonClicked); |
| 84 |
| 85 CustomDrawButton* close_button() const { return close_button_.get(); } |
| 86 CustomDrawButton* minimize_button() const { return minimize_button_.get(); } |
| 87 CustomDrawButton* restore_button() const { return restore_button_.get(); } |
| 58 | 88 |
| 59 SkColor GetTextColor() const; | 89 SkColor GetTextColor() const; |
| 60 | 90 |
| 91 // Pointers to the browser window that owns us and its GtkWindow. |
| 61 PanelBrowserWindowGtk* browser_window_; | 92 PanelBrowserWindowGtk* browser_window_; |
| 93 GtkWindow* window_; |
| 62 | 94 |
| 63 // All other buttons, including close and minimize buttons, are defined in | 95 // The container widget the holds the hbox which contains the whole titlebar. |
| 64 // the base class BrowserTitlebar. This is indeed our restore button. But | 96 GtkWidget* container_; |
| 65 // we name it differently to avoid the confusion with restore_button defined | 97 |
| 66 // in the base class and used for unmaximize purpose. | 98 // VBoxes that holds the minimize/restore/close buttons box. |
| 67 scoped_ptr<CustomDrawButton> unminimize_button_; | 99 GtkWidget* titlebar_right_buttons_vbox_; |
| 100 |
| 101 // HBoxes that contains the actual min/max/close buttons. |
| 102 GtkWidget* titlebar_right_buttons_hbox_; |
| 103 |
| 104 // The icon and page title. |
| 105 GtkWidget* icon_; |
| 106 GtkWidget* title_; |
| 107 |
| 108 // The buttons. |
| 109 scoped_ptr<CustomDrawButton> close_button_; |
| 110 scoped_ptr<CustomDrawButton> minimize_button_; |
| 111 scoped_ptr<CustomDrawButton> restore_button_; |
| 112 |
| 113 TitlebarThrobAnimation throbber_; |
| 114 GtkThemeService* theme_service_; |
| 115 content::NotificationRegistrar registrar_; |
| 68 | 116 |
| 69 DISALLOW_COPY_AND_ASSIGN(PanelBrowserTitlebarGtk); | 117 DISALLOW_COPY_AND_ASSIGN(PanelBrowserTitlebarGtk); |
| 70 }; | 118 }; |
| 71 | 119 |
| 72 #endif // CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ | 120 #endif // CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ |
| OLD | NEW |