summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc91
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h24
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc143
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h88
4 files changed, 257 insertions, 89 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index b218beb..c51d27d 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -11,8 +11,9 @@
#include "base/path_service.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
-#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/back_forward_menu_model_gtk.h"
+#include "chrome/browser/gtk/custom_button.h"
+#include "chrome/browser/gtk/location_bar_view_gtk.h"
#include "chrome/browser/gtk/standard_menus.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/common/l10n_util.h"
@@ -21,17 +22,19 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-// TODO(deanm): Remove this when the LocationBarView is used.
-class LocationBar;
-
const int BrowserToolbarGtk::kToolbarHeight = 38;
// For the back/forward dropdown menus, the time in milliseconds between
// when the user clicks and the popup menu appears.
static const int kMenuTimerDelay = 500;
+static void OnGrabFocusThunk(GtkWidget* toolbar, gpointer self) {
+ reinterpret_cast<BrowserToolbarGtk*>(self)->FocusLocationBar();
+}
+
BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser)
: toolbar_(NULL),
- entry_(NULL),
+ location_bar_(new LocationBarViewGtk(browser->command_updater(),
+ browser->toolbar_model())),
model_(browser->toolbar_model()),
browser_(browser),
profile_(NULL),
@@ -52,6 +55,9 @@ BrowserToolbarGtk::~BrowserToolbarGtk() {
}
void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) {
+ // Make sure to tell the location bar the profile before calling its Init.
+ SetProfile(profile);
+
accel_group_ = accel_group;
show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this);
@@ -89,22 +95,17 @@ void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) {
star_.reset(BuildToolbarButton(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D,
l10n_util::GetString(IDS_TOOLTIP_STAR)));
- entry_ = gtk_entry_new();
- gtk_widget_set_size_request(entry_, 0, 27);
- g_signal_connect(G_OBJECT(entry_), "activate",
- G_CALLBACK(OnEntryActivate), this);
- g_signal_connect(G_OBJECT(entry_), "focus",
- G_CALLBACK(OnEntryFocus), this);
- g_signal_connect(G_OBJECT(entry_), "focus-in-event",
- G_CALLBACK(OnEntryFocusIn), this);
- g_signal_connect(G_OBJECT(entry_), "focus-out-event",
- G_CALLBACK(OnEntryFocusOut), this);
+ location_bar_->Init();
+ gtk_box_pack_start(GTK_BOX(toolbar_), location_bar_->widget(), TRUE, TRUE, 0);
+
+ // We listen for ctrl-l which we have send a grab-focus action to the
+ // toolbar. We want our callback to just call FocusLocationBar().
+ g_signal_connect(toolbar_, "grab-focus",
+ G_CALLBACK(OnGrabFocusThunk), this);
gtk_widget_add_accelerator(
- entry_, "grab-focus", accel_group_, GDK_l,
+ toolbar_, "grab-focus", accel_group_, GDK_l,
GDK_CONTROL_MASK, GtkAccelFlags(0));
- gtk_box_pack_start(GTK_BOX(toolbar_), entry_, TRUE, TRUE, 0);
-
go_.reset(BuildToolbarButton(IDR_GO, IDR_GO_P, IDR_GO_H, 0, L""));
gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0);
@@ -117,8 +118,6 @@ void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) {
l10n_util::GetStringF(IDS_APPMENU_TOOLTIP,
l10n_util::GetString(IDS_PRODUCT_NAME))));
app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_));
-
- SetProfile(profile);
}
void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) {
@@ -126,12 +125,11 @@ void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) {
}
LocationBar* BrowserToolbarGtk::GetLocationBar() const {
- NOTIMPLEMENTED();
- return NULL;
+ return location_bar_.get();
}
void BrowserToolbarGtk::FocusLocationBar() {
- gtk_widget_grab_focus(entry_);
+ location_bar_->FocusLocation();
}
void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) {
@@ -195,16 +193,12 @@ void BrowserToolbarGtk::SetProfile(Profile* profile) {
return;
profile_ = profile;
- // TODO(erg): location_bar_ is a normal gtk text box right now. Change this
- // when we get omnibox support.
- // location_bar_->SetProfile(profile);
+ location_bar_->SetProfile(profile);
}
void BrowserToolbarGtk::UpdateTabContents(TabContents* contents,
bool should_restore_state) {
- // Extract the UTF-8 representation of the URL.
- gtk_entry_set_text(GTK_ENTRY(entry_),
- contents->GetURL().possibly_invalid_spec().c_str());
+ location_bar_->Update(should_restore_state ? contents : NULL);
}
CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton(
@@ -249,45 +243,6 @@ CustomContainerButton* BrowserToolbarGtk::BuildToolbarMenuButton(
}
// static
-void BrowserToolbarGtk::OnEntryActivate(GtkEntry *entry,
- BrowserToolbarGtk* toolbar) {
- GURL dest(URLFixerUpper::FixupURL(std::string(gtk_entry_get_text(entry)),
- std::string()));
- toolbar->browser_->GetSelectedTabContents()->
- OpenURL(dest, GURL(), CURRENT_TAB, PageTransition::TYPED);
-}
-
-// static
-gboolean BrowserToolbarGtk::OnEntryFocus(GtkWidget* widget,
- GtkDirectionType direction,
- BrowserToolbarGtk* host) {
- if (!GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_widget_grab_focus(widget);
- return TRUE;
- }
-
- return FALSE;
-}
-
-// static
-gboolean BrowserToolbarGtk::OnEntryFocusIn(GtkWidget* widget,
- GdkEventFocus* focus,
- BrowserToolbarGtk* host) {
- // Set the caret at the end of the text.
- gtk_editable_set_position(GTK_EDITABLE(widget), -1);
- return FALSE;
-}
-
-// static
-gboolean BrowserToolbarGtk::OnEntryFocusOut(GtkWidget* widget,
- GdkEventFocus* focus,
- BrowserToolbarGtk* host) {
- // Clear the selected text (if any).
- gtk_editable_set_position(GTK_EDITABLE(widget), 0);
- return FALSE;
-}
-
-// static
void BrowserToolbarGtk::OnButtonClick(GtkWidget* button,
BrowserToolbarGtk* toolbar) {
int tag = -1;
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index c943db4..9e854fd 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -19,6 +19,7 @@ class Browser;
class CustomContainerButton;
class CustomDrawButton;
class LocationBar;
+class LocationBarViewGtk;
class Profile;
class TabContents;
class ToolbarModel;
@@ -83,25 +84,6 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
unsigned int accelerator,
unsigned int accelerator_mod);
- // Gtk callback for the "activate" signal on the |entry_| widget. Responds to
- // enter.
- static void OnEntryActivate(GtkEntry *entry, BrowserToolbarGtk* toolbar);
-
- // Gtk callback for the "focus" signal on the |entry_| widget.
- static gboolean OnEntryFocus(GtkWidget* widget,
- GtkDirectionType direction,
- BrowserToolbarGtk* host);
-
- // Gtk callback for the "focus-in" signal on the |entry_| widget.
- static gboolean OnEntryFocusIn(GtkWidget* widget,
- GdkEventFocus* focus,
- BrowserToolbarGtk* host);
-
- // Gtk callback for the "focus-out" signal on the |entry_| widget.
- static gboolean OnEntryFocusOut(GtkWidget* widget,
- GdkEventFocus* focus,
- BrowserToolbarGtk* host);
-
// Gtk callback for the "clicked" signal.
static void OnButtonClick(GtkWidget* button, BrowserToolbarGtk* toolbar);
@@ -126,8 +108,8 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
// Tooltip container for all GTK widgets in this class.
GtkTooltips* toolbar_tooltips_;
- // Our temporary URL bar (until we get the omnibox up).
- GtkWidget* entry_;
+ // The location bar view.
+ scoped_ptr<LocationBarViewGtk> location_bar_;
// A pointer to our window's accelerator list.
GtkAccelGroup* accel_group_;
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
new file mode 100644
index 0000000..4e97032
--- /dev/null
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -0,0 +1,143 @@
+#include "chrome/browser/gtk/location_bar_view_gtk.h"
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/alternate_nav_url_fetcher.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
+#include "chrome/browser/command_updater.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/page_transition_types.h"
+#include "skia/include/SkBitmap.h"
+#include "webkit/glue/window_open_disposition.h"
+
+LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
+ ToolbarModel* toolbar_model)
+ : vbox_(NULL),
+ profile_(NULL),
+ command_updater_(command_updater),
+ toolbar_model_(toolbar_model),
+ disposition_(CURRENT_TAB),
+ transition_(PageTransition::TYPED) {
+}
+
+LocationBarViewGtk::~LocationBarViewGtk(){
+ // TODO(deanm): Should I destroy the widgets here, or leave it up to the
+ // embedder? When the embedder destroys their widget, if we're a child, we
+ // will also get destroyed, so the ownership is kinda unclear.
+}
+
+void LocationBarViewGtk::Init(){
+ edit_view_.reset(new AutocompleteEditViewGtk(this, toolbar_model_, profile_,
+ command_updater_));
+ edit_view_->Init();
+
+ vbox_ = gtk_vbox_new(false, 0);
+
+ // Get the location bar to fit nicely in the toolbar, kinda ugly.
+ static const int kTopPadding = 2;
+ static const int kBottomPadding = 3;
+ GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1);
+ gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
+ kTopPadding, kBottomPadding, 0, 0);
+ gtk_container_add(GTK_CONTAINER(alignment), edit_view_->widget());
+
+ gtk_box_pack_start(GTK_BOX(vbox_), alignment, TRUE, TRUE, 0);
+}
+
+void LocationBarViewGtk::SetProfile(Profile* profile) {
+ profile_ = profile;
+}
+
+void LocationBarViewGtk::Update(const TabContents* contents) {
+ edit_view_->Update(contents);
+}
+
+void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url) {
+ if (!url.is_valid())
+ return;
+
+ location_input_ = UTF8ToWide(url.spec());
+ disposition_ = disposition;
+ transition_ = transition;
+
+ if (!command_updater_)
+ return;
+
+ if (!alternate_nav_url.is_valid()) {
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ return;
+ }
+
+ scoped_ptr<AlternateNavURLFetcher> fetcher(
+ new AlternateNavURLFetcher(alternate_nav_url));
+ // The AlternateNavURLFetcher will listen for the pending navigation
+ // notification that will be issued as a result of the "open URL." It
+ // will automatically install itself into that navigation controller.
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
+ // I'm not sure this should be reachable, but I'm not also sure enough
+ // that it shouldn't to stick in a NOTREACHED(). In any case, this is
+ // harmless; we can simply let the fetcher get deleted here and it will
+ // clean itself up properly.
+ } else {
+ fetcher.release(); // The navigation controller will delete the fetcher.
+ }
+}
+
+void LocationBarViewGtk::OnChanged() {
+ // TODO(deanm): Here is where we would do layout when we have things like
+ // the keyword display, ssl icons, etc.
+}
+
+void LocationBarViewGtk::OnInputInProgress(bool in_progress) {
+ NOTIMPLEMENTED();
+}
+
+SkBitmap LocationBarViewGtk::GetFavIcon() const {
+ NOTIMPLEMENTED();
+ return SkBitmap();
+}
+
+std::wstring LocationBarViewGtk::GetTitle() const {
+ NOTIMPLEMENTED();
+ return std::wstring();
+}
+
+void LocationBarViewGtk::ShowFirstRunBubble(){
+ NOTIMPLEMENTED();
+}
+
+std::wstring LocationBarViewGtk::GetInputString() const{
+ return location_input_;
+}
+
+WindowOpenDisposition LocationBarViewGtk::GetWindowOpenDisposition() const{
+ return disposition_;
+}
+
+PageTransition::Type LocationBarViewGtk::GetPageTransition() const{
+ return transition_;
+}
+
+void LocationBarViewGtk::AcceptInput(){
+ NOTIMPLEMENTED();
+}
+
+void LocationBarViewGtk::FocusLocation(){
+ edit_view_->FocusLocation();
+}
+
+void LocationBarViewGtk::FocusSearch(){
+ NOTIMPLEMENTED();
+}
+
+void LocationBarViewGtk::SaveStateToContents(TabContents* contents){
+ NOTIMPLEMENTED();
+}
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
new file mode 100644
index 0000000..50b0775
--- /dev/null
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -0,0 +1,88 @@
+// 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_LOCATION_BAR_VIEW_GTK_H_
+#define CHROME_BROWSER_GTK_LOCATION_BAR_VIEW_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/location_bar.h"
+#include "chrome/common/page_transition_types.h"
+#include "webkit/glue/window_open_disposition.h"
+
+class AutocompleteEditViewGtk;
+class CommandUpdater;
+class Profile;
+class SkBitmap;
+class TabContents;
+class ToolbarModel;
+
+class LocationBarViewGtk : public AutocompleteEditController,
+ public LocationBar {
+ public:
+ LocationBarViewGtk(CommandUpdater* command_updater,
+ ToolbarModel* toolbar_model);
+ ~LocationBarViewGtk();
+
+ void Init();
+
+ void SetProfile(Profile* profile);
+
+ // Return the native vbox widget. You must call Init() first, or the result
+ // will be NULL. This is the widget that an embedder should host.
+ GtkWidget* widget() { return vbox_; }
+
+ // Updates the location bar. We also reset the bar's permanent text and
+ // security style, and, if |tab_for_state_restoring| is non-NULL, also
+ // restore saved state that the tab holds.
+ void Update(const TabContents* tab_for_state_restoring);
+
+ // Implement the AutocompleteEditController interface.
+ virtual void OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url);
+ virtual void OnChanged();
+ virtual void OnInputInProgress(bool in_progress);
+ virtual SkBitmap GetFavIcon() const;
+ virtual std::wstring GetTitle() const;
+
+ // Implement the LocationBar interface.
+ virtual void ShowFirstRunBubble();
+ virtual std::wstring GetInputString() const;
+ virtual WindowOpenDisposition GetWindowOpenDisposition() const;
+ virtual PageTransition::Type GetPageTransition() const;
+ virtual void AcceptInput();
+ virtual void FocusLocation();
+ virtual void FocusSearch();
+ virtual void SaveStateToContents(TabContents* contents);
+
+ private:
+ GtkWidget* vbox_;
+
+ scoped_ptr<AutocompleteEditViewGtk> edit_view_;
+
+ Profile* profile_;
+ CommandUpdater* command_updater_;
+ ToolbarModel* toolbar_model_;
+
+ // When we get an OnAutocompleteAccept notification from the autocomplete
+ // edit, we save the input string so we can give it back to the browser on
+ // the LocationBar interface via GetInputString().
+ std::wstring location_input_;
+
+ // The user's desired disposition for how their input should be opened
+ WindowOpenDisposition disposition_;
+
+ // The transition type to use for the navigation
+ PageTransition::Type transition_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtk);
+};
+
+#endif // CHROME_BROWSER_GTK_LOCATION_BAR_VIEW_GTK_H_