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 #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 bool BuildButton(const std::string& button_token); | |
|
jennb
2012/06/05 20:40:35
I don't see BuildButton in panel_browser_titlebar_
jianli
2012/06/05 21:03:40
Removed.
| |
| 70 CustomDrawButton* CreateButton(panel::TitlebarButtonType button_type); | |
| 71 void GetButtonResources(panel::TitlebarButtonType button_type, | |
| 72 int* normal_image_id, | |
| 73 int* pressed_image_id, | |
| 74 int* hover_image_id, | |
| 75 int* tooltip_id) const; | |
| 76 GtkWidget* GetButtonHBox(); | |
| 77 | |
| 78 // Callback for changes to window state. This includes minimizing/restoring | |
| 79 // the window. | |
| 80 CHROMEG_CALLBACK_1(PanelBrowserTitlebarGtk, gboolean, OnWindowStateChanged, | |
| 81 GtkWindow*, GdkEventWindowState*); | |
| 82 | |
| 83 // Callback for minimize/restore/close buttons. | |
| 84 CHROMEGTK_CALLBACK_0(PanelBrowserTitlebarGtk, void, OnButtonClicked); | |
| 85 | |
| 86 CustomDrawButton* close_button() const { return close_button_.get(); } | |
| 87 CustomDrawButton* minimize_button() const { return minimize_button_.get(); } | |
| 88 CustomDrawButton* restore_button() const { return restore_button_.get(); } | |
| 58 | 89 |
| 59 SkColor GetTextColor() const; | 90 SkColor GetTextColor() const; |
| 60 | 91 |
| 92 // Pointers to the browser window that owns us and its GtkWindow. | |
| 61 PanelBrowserWindowGtk* browser_window_; | 93 PanelBrowserWindowGtk* browser_window_; |
| 94 GtkWindow* window_; | |
| 62 | 95 |
| 63 // All other buttons, including close and minimize buttons, are defined in | 96 // The container widget the holds the hbox which contains the whole titlebar. |
| 64 // the base class BrowserTitlebar. This is indeed our restore button. But | 97 GtkWidget* container_; |
| 65 // we name it differently to avoid the confusion with restore_button defined | 98 |
| 66 // in the base class and used for unmaximize purpose. | 99 // VBoxes that holds the minimize/restore/close buttons box. |
| 67 scoped_ptr<CustomDrawButton> unminimize_button_; | 100 GtkWidget* titlebar_right_buttons_vbox_; |
| 101 | |
| 102 // HBoxes that contains the actual min/max/close buttons. | |
| 103 GtkWidget* titlebar_right_buttons_hbox_; | |
| 104 | |
| 105 // The icon and page title. | |
| 106 GtkWidget* icon_; | |
| 107 GtkWidget* title_; | |
| 108 | |
| 109 // The buttons. | |
| 110 scoped_ptr<CustomDrawButton> close_button_; | |
| 111 scoped_ptr<CustomDrawButton> minimize_button_; | |
| 112 scoped_ptr<CustomDrawButton> restore_button_; | |
| 113 | |
| 114 TitlebarThrobAnimation throbber_; | |
| 115 GtkThemeService* theme_service_; | |
| 116 content::NotificationRegistrar registrar_; | |
| 68 | 117 |
| 69 DISALLOW_COPY_AND_ASSIGN(PanelBrowserTitlebarGtk); | 118 DISALLOW_COPY_AND_ASSIGN(PanelBrowserTitlebarGtk); |
| 70 }; | 119 }; |
| 71 | 120 |
| 72 #endif // CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ | 121 #endif // CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_ |
| OLD | NEW |