summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/options/url_picker_dialog_gtk.h
blob: a911cc7b8940b342cbbcb7bfbbe363e835e51c5d (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
// 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_OPTIONS_URL_PICKER_DIALOG_GTK_H_
#define CHROME_BROWSER_GTK_OPTIONS_URL_PICKER_DIALOG_GTK_H_

#include <string>

#include "app/gtk_signal.h"
#include "base/basictypes.h"
#include "base/callback.h"
#include "chrome/browser/gtk/gtk_tree.h"
#include "chrome/browser/history/history.h"

class AccessibleWidgetHelper;
class GURL;
class Profile;
class PossibleURLModel;

class UrlPickerDialogGtk : public gtk_tree::TableAdapter::Delegate {
 public:
  typedef Callback1<const GURL&>::Type UrlPickerCallback;

  UrlPickerDialogGtk(UrlPickerCallback* callback,
                     Profile* profile,
                     GtkWindow* parent);

  ~UrlPickerDialogGtk();

  // gtk_tree::TableAdapter::Delegate implementation.
  virtual void SetColumnValues(int row, GtkTreeIter* iter);

 private:
  // Call the callback based on url entry.
  void AddURL();

  // Set sensitivity of buttons based on url entry state.
  void EnableControls();

  // Return the entry-formatted url for path in the sorted model.
  std::string GetURLForPath(GtkTreePath* path) const;

  // GTK sorting callbacks.
  static gint CompareTitle(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b,
                           gpointer window);
  static gint CompareURL(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b,
                         gpointer window);

  CHROMEGTK_CALLBACK_0(UrlPickerDialogGtk, void, OnUrlEntryChanged);
  CHROMEGTK_CALLBACK_2(UrlPickerDialogGtk, void, OnHistoryRowActivated,
                       GtkTreePath*, GtkTreeViewColumn*);
  CHROMEGTK_CALLBACK_1(UrlPickerDialogGtk, void, OnResponse, int);
  CHROMEGTK_CALLBACK_0(UrlPickerDialogGtk, void, OnWindowDestroy);

  // Callback for user selecting rows in recent history list.
  static void OnHistorySelectionChanged(GtkTreeSelection* selection,
                                        UrlPickerDialogGtk* window);

  // The dialog window.
  GtkWidget* dialog_;

  // The text entry for manually adding an URL.
  GtkWidget* url_entry_;

  // The add button (we need a reference to it so we can de-activate it when the
  // |url_entry_| is empty.)
  GtkWidget* add_button_;

  // The recent history list.
  GtkWidget* history_tree_;
  GtkListStore* history_list_store_;
  GtkTreeModel* history_list_sort_;
  GtkTreeSelection* history_selection_;

  // Profile.
  Profile* profile_;

  // The table model.
  scoped_ptr<PossibleURLModel> url_table_model_;
  scoped_ptr<gtk_tree::TableAdapter> url_table_adapter_;

  // Called if the user selects an url.
  UrlPickerCallback* callback_;

  // Helper object to manage accessibility metadata.
  scoped_ptr<AccessibleWidgetHelper> accessible_widget_helper_;

  DISALLOW_COPY_AND_ASSIGN(UrlPickerDialogGtk);
};

#endif  // CHROME_BROWSER_GTK_OPTIONS_URL_PICKER_DIALOG_GTK_H_