summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/panels/panel_browser_titlebar_gtk.h
blob: 954d76265991230c68830ebfdcbbe2c4c3c1ddd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_
#define CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_

#include <gtk/gtk.h>

#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/gtk/browser_titlebar_base.h"
#include "chrome/browser/ui/gtk/titlebar_throb_animation.h"
#include "chrome/browser/ui/panels/panel_constants.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/gfx/skia_util.h"

class CustomDrawButton;
class GtkThemeService;
class PanelBrowserWindowGtk;

namespace content {
class WebContents;
}

class PanelBrowserTitlebarGtk : public BrowserTitlebarBase,
                                public content::NotificationObserver {
 public:
  PanelBrowserTitlebarGtk(PanelBrowserWindowGtk* browser_window,
                          GtkWindow* window);
  virtual ~PanelBrowserTitlebarGtk();

  void UpdateTextColor();
  void UpdateMinimizeRestoreButtonVisibility();

  // When a panel appears in the same position as the one of the panel being
  // closed and the cursor stays in the close button, the close button appears
  // not to be clickable. This is because neither "enter-notify-event" nor
  // "clicked" event for the new panel gets fired if the mouse does not move.
  // This creates a bad experience when a user has multiple panels of the same
  // size (which is typical) and tries closing them all by repeatedly clicking
  // in the same place on the screen.
  //
  // Opened a gtk bug for this -
  //   https://bugzilla.gnome.org/show_bug.cgi?id=667841
  void SendEnterNotifyToCloseButtonIfUnderMouse();

  // Overriden from BrowserTitlebarBase.
  virtual void Init() OVERRIDE;
  virtual void UpdateTitleAndIcon() OVERRIDE;
  virtual void UpdateCustomFrame(bool use_custom_frame) OVERRIDE;
  virtual void UpdateThrobber(content::WebContents* web_contents) OVERRIDE;
  virtual void ShowContextMenu(GdkEventButton* event) OVERRIDE;
  virtual GtkWidget* widget() const OVERRIDE;
  virtual void set_window(GtkWindow* window) OVERRIDE;
  virtual AvatarMenuButtonGtk* avatar_button() const OVERRIDE;

 private:
  friend class NativePanelTestingGtk;

  // Overridden from content::NotificationObserver:
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

  void BuildButtons();
  CustomDrawButton* CreateButton(panel::TitlebarButtonType button_type);
  void GetButtonResources(panel::TitlebarButtonType button_type,
                          int* normal_image_id,
                          int* pressed_image_id,
                          int* hover_image_id,
                          int* tooltip_id) const;
  GtkWidget* GetButtonHBox();

  // Callback for changes to window state.  This includes minimizing/restoring
  // the window.
  CHROMEG_CALLBACK_1(PanelBrowserTitlebarGtk, gboolean, OnWindowStateChanged,
                     GtkWindow*, GdkEventWindowState*);

  // Callback for minimize/restore/close buttons.
  CHROMEGTK_CALLBACK_0(PanelBrowserTitlebarGtk, void, OnButtonClicked);

  CustomDrawButton* close_button() const { return close_button_.get(); }
  CustomDrawButton* minimize_button() const { return minimize_button_.get(); }
  CustomDrawButton* restore_button() const { return restore_button_.get(); }

  SkColor GetTextColor() const;

  // Pointers to the browser window that owns us and its GtkWindow.
  PanelBrowserWindowGtk* browser_window_;
  GtkWindow* window_;

  // The container widget the holds the hbox which contains the whole titlebar.
  GtkWidget* container_;

  // VBoxes that holds the minimize/restore/close buttons box.
  GtkWidget* titlebar_right_buttons_vbox_;

  // HBoxes that contains the actual min/max/close buttons.
  GtkWidget* titlebar_right_buttons_hbox_;

  // The icon and page title.
  GtkWidget* icon_;
  GtkWidget* title_;

  // The buttons.
  scoped_ptr<CustomDrawButton> close_button_;
  scoped_ptr<CustomDrawButton> minimize_button_;
  scoped_ptr<CustomDrawButton> restore_button_;

  TitlebarThrobAnimation throbber_;
  GtkThemeService* theme_service_;
  content::NotificationRegistrar registrar_;

  DISALLOW_COPY_AND_ASSIGN(PanelBrowserTitlebarGtk);
};

#endif  // CHROME_BROWSER_UI_PANELS_PANEL_BROWSER_TITLEBAR_GTK_H_