summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/toolbar_star_toggle_gtk.h
blob: faa025a50ab3b516cd7aade42331d750446b9a75 (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
// Copyright (c) 2010 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_GTK_TOOLBAR_STAR_TOGGLE_GTK_H_
#define CHROME_BROWSER_GTK_TOOLBAR_STAR_TOGGLE_GTK_H_

#include <gtk/gtk.h>

#include "base/basictypes.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/owned_widget_gtk.h"

class BrowserToolbarGtk;
class GtkThemeProvider;
class GURL;

// Displays the bookmark star button, which toggles between two images.
class ToolbarStarToggleGtk : public NotificationObserver {
 public:
  explicit ToolbarStarToggleGtk(BrowserToolbarGtk* host);
  ~ToolbarStarToggleGtk();

  // Provide NotificationObserver implementation.
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  // If the bubble isn't showing, shows it above the star button.
  void ShowStarBubble(const GURL& url, bool newly_bookmarked);

  void SetStarred(bool starred);

  GtkWidget* widget() const { return widget_.get(); }

 private:
  // Updates the properties of |widget_| when we would need to change its
  // state.
  void UpdateGTKButton();

  // Callback for expose, used to draw the custom graphics.
  static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e,
                           ToolbarStarToggleGtk* obj);

  // Callback to get the data associated with a drag.
  static void OnDragDataGet(GtkWidget* widget,
                            GdkDragContext* drag_context,
                            GtkSelectionData* data,
                            guint info,
                            guint time,
                            ToolbarStarToggleGtk* star);

  // Used to listen for theme change notifications.
  NotificationRegistrar registrar_;

  // The browser toolbar hosting this widget, for getting the current profile.
  BrowserToolbarGtk* host_;

  // The actual button widget.
  OwnedWidgetGtk widget_;

  // Whether we show the yellow star.
  bool is_starred_;

  GtkThemeProvider* theme_provider_;

  CustomDrawButtonBase unstarred_;
  CustomDrawButtonBase starred_;
  CustomDrawHoverController hover_controller_;

  DISALLOW_COPY_AND_ASSIGN(ToolbarStarToggleGtk);
};

#endif  // CHROME_BROWSER_GTK_TOOLBAR_STAR_TOGGLE_GTK_H_