summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/back_forward_button_gtk.h
blob: 49ea05f25036d841f4f30be017a602f906e7ac45 (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
// Copyright (c) 2009 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_BACK_FORWARD_BUTTON_GTK_H_
#define CHROME_BROWSER_GTK_BACK_FORWARD_BUTTON_GTK_H_

#include "base/scoped_ptr.h"
#include "base/task.h"
#include "chrome/browser/gtk/custom_button.h"

class BackForwardMenuModelGtk;
class Browser;
class MenuGtk;

typedef struct _GtkWidget GtkWidget;

// When clicked, these buttons will navigate forward or backward. When
// pressed and held, they show a dropdown menu of recent web sites.
class BackForwardButtonGtk {
 public:
  BackForwardButtonGtk(Browser* browser, bool is_forward);
  virtual ~BackForwardButtonGtk();

  // The dropdown menu is no longer showing.
  void StoppedShowingMenu();

  GtkWidget* widget() { return button_->widget(); }

 private:
  // Executes the browser command.
  static void OnClick(GtkWidget* widget, BackForwardButtonGtk* button);

  // Starts a timer to show the dropdown menu.
  static gboolean OnButtonPress(GtkWidget* button,
                                GdkEventButton* event,
                                BackForwardButtonGtk* toolbar);

  // If there is a timer to show the dropdown menu, and the mouse has moved
  // sufficiently down the screen, cancel the timer and immediately show the
  // menu.
  static gboolean OnMouseMove(GtkWidget* widget,
                              GdkEventMotion* event,
                              BackForwardButtonGtk* toolbar);

  // Shows the dropdown menu.
  void ShowBackForwardMenu();

  // The menu gets reset every time it is shown.
  scoped_ptr<MenuGtk> menu_;

  scoped_ptr<CustomDrawButton> button_;

  // The browser to which we will send commands.
  Browser* browser_;

  // Whether this button is a forward button.
  bool is_forward_;

  // The dropdown menu delegate.
  scoped_ptr<BackForwardMenuModelGtk> menu_model_;

  // The y position of the last mouse down event.
  int y_position_of_last_press_;

  ScopedRunnableMethodFactory<BackForwardButtonGtk> show_menu_factory_;

  DISALLOW_COPY_AND_ASSIGN(BackForwardButtonGtk);
};

#endif  // CHROME_BROWSER_GTK_BACK_FORWARD_BUTTON_GTK_H_