summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 16:56:27 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 16:56:27 +0000
commitfd4504be3c2de832ae20aadc92d3581ac71b2d58 (patch)
treebdc624fb6ff6a9c60f72fb0afb9dfb9d7af3f79e /chrome
parente8fab856ad84b068d841f9eef727424c1eea7460 (diff)
downloadchromium_src-fd4504be3c2de832ae20aadc92d3581ac71b2d58.zip
chromium_src-fd4504be3c2de832ae20aadc92d3581ac71b2d58.tar.gz
chromium_src-fd4504be3c2de832ae20aadc92d3581ac71b2d58.tar.bz2
Some cleanups and hookups to LocationBarViewGtk.
- Rename FocusLocation to SetFocus (and don't make it select all). This matches the Windows style more closely. - Implement SetUserText (basically copied from Windows w/ a TODO). - Switch to the gtk_accel APIs instead of using the widget ones. - Hookup FocusSearch (and its ctrl-k accelerator). - Hookup AcceptInput (the go button now works!). - Fix lack of space before { - Rename edit_view_ to location_entry_ to match the Windows LocationBarView. - Don't plumb FocusLocationBar through BrowserWindow -> BrowserToolbar. Review URL: http://codereview.chromium.org/43025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11339 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc10
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h2
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc37
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h3
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc5
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc40
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h2
7 files changed, 58 insertions, 41 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index cae7c6e..4c21fc3 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -100,9 +100,8 @@ void AutocompleteEditViewGtk::Init() {
G_CALLBACK(&HandleViewMoveCursorThunk), this);
}
-void AutocompleteEditViewGtk::FocusLocation() {
+void AutocompleteEditViewGtk::SetFocus() {
gtk_widget_grab_focus(text_view_);
- SelectAll(false);
}
void AutocompleteEditViewGtk::SaveStateToTab(TabContents* tab) {
@@ -160,7 +159,12 @@ std::wstring AutocompleteEditViewGtk::GetText() const {
void AutocompleteEditViewGtk::SetUserText(const std::wstring& text,
const std::wstring& display_text,
bool update_popup) {
- NOTIMPLEMENTED();
+ model_->SetUserText(text);
+ // TODO(deanm): something about selection / focus change here.
+ SetWindowTextAndCaretPos(display_text, display_text.length());
+ if (update_popup)
+ UpdatePopup();
+ TextChanged();
}
void AutocompleteEditViewGtk::SetWindowTextAndCaretPos(const std::wstring& text,
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 85d16ae..f3f1d9f 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -37,7 +37,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
GtkWidget* widget() { return text_view_; }
// Grab keyboard input focus, putting focus on the location widget.
- void FocusLocation();
+ void SetFocus();
// Implement the AutocompleteEditView interface.
virtual AutocompleteEditModel* model() { return model_.get(); }
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index c51d27d..0196267 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -27,8 +27,22 @@ const int BrowserToolbarGtk::kToolbarHeight = 38;
// 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();
+gboolean OnAccelerator(GtkAccelGroup* accel_group,
+ GObject* acceleratable,
+ guint keyval,
+ GdkModifierType modifier,
+ gpointer userdata) {
+ BrowserToolbarGtk* self = reinterpret_cast<BrowserToolbarGtk*>(userdata);
+ switch (keyval) {
+ case GDK_l:
+ self->GetLocationBar()->FocusLocation();
+ return TRUE;
+ case GDK_k:
+ self->GetLocationBar()->FocusSearch();
+ return TRUE;
+ default:
+ return FALSE;
+ }
}
BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser)
@@ -98,13 +112,14 @@ void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) {
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(
- toolbar_, "grab-focus", accel_group_, GDK_l,
- GDK_CONTROL_MASK, GtkAccelFlags(0));
+ // Map ctrl-l for setting focus to the location entry.
+ gtk_accel_group_connect(
+ accel_group_, GDK_l, GDK_CONTROL_MASK, GtkAccelFlags(0),
+ g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL));
+ // Map ctrl-k for setting focus to a search in the location entry.
+ gtk_accel_group_connect(
+ accel_group_, GDK_k, GDK_CONTROL_MASK, GtkAccelFlags(0),
+ g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL));
go_.reset(BuildToolbarButton(IDR_GO, IDR_GO_P, IDR_GO_H, 0, L""));
@@ -128,10 +143,6 @@ LocationBar* BrowserToolbarGtk::GetLocationBar() const {
return location_bar_.get();
}
-void BrowserToolbarGtk::FocusLocationBar() {
- location_bar_->FocusLocation();
-}
-
void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) {
GtkWidget* widget = NULL;
switch (id) {
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index 9e854fd..200fe28 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -44,9 +44,6 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
virtual LocationBar* GetLocationBar() const;
- // Set focus on the entry box.
- void FocusLocationBar();
-
// Overridden from CommandUpdater::CommandObserver:
virtual void EnabledStateChangedForCommand(int id, bool enabled);
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index a0b9d50..8ac350e 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -8,10 +8,11 @@
#include "base/base_paths_linux.h"
#include "base/path_service.h"
#include "chrome/browser/browser.h"
-#include "chrome/browser/gtk/nine_box.h"
#include "chrome/browser/gtk/browser_toolbar_gtk.h"
+#include "chrome/browser/gtk/nine_box.h"
#include "chrome/browser/gtk/status_bubble_gtk.h"
#include "chrome/browser/gtk/tab_contents_container_gtk.h"
+#include "chrome/browser/location_bar.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/tab_contents/web_contents.h"
@@ -275,7 +276,7 @@ LocationBar* BrowserWindowGtk::GetLocationBar() const {
}
void BrowserWindowGtk::SetFocusToLocationBar() {
- toolbar_->FocusLocationBar();
+ GetLocationBar()->FocusLocation();
}
void BrowserWindowGtk::UpdateStopGoState(bool is_loading) {
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index b93c617..d1f52a8 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -28,16 +28,18 @@ LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
transition_(PageTransition::TYPED) {
}
-LocationBarViewGtk::~LocationBarViewGtk(){
+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();
+void LocationBarViewGtk::Init() {
+ location_entry_.reset(new AutocompleteEditViewGtk(this,
+ toolbar_model_,
+ profile_,
+ command_updater_));
+ location_entry_->Init();
vbox_ = gtk_vbox_new(false, 0);
@@ -47,7 +49,7 @@ void LocationBarViewGtk::Init(){
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_container_add(GTK_CONTAINER(alignment), location_entry_->widget());
gtk_box_pack_start(GTK_BOX(vbox_), alignment, TRUE, TRUE, 0);
}
@@ -57,7 +59,7 @@ void LocationBarViewGtk::SetProfile(Profile* profile) {
}
void LocationBarViewGtk::Update(const TabContents* contents) {
- edit_view_->Update(contents);
+ location_entry_->Update(contents);
}
void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
@@ -114,34 +116,36 @@ std::wstring LocationBarViewGtk::GetTitle() const {
return std::wstring();
}
-void LocationBarViewGtk::ShowFirstRunBubble(){
+void LocationBarViewGtk::ShowFirstRunBubble() {
NOTIMPLEMENTED();
}
-std::wstring LocationBarViewGtk::GetInputString() const{
+std::wstring LocationBarViewGtk::GetInputString() const {
return location_input_;
}
-WindowOpenDisposition LocationBarViewGtk::GetWindowOpenDisposition() const{
+WindowOpenDisposition LocationBarViewGtk::GetWindowOpenDisposition() const {
return disposition_;
}
-PageTransition::Type LocationBarViewGtk::GetPageTransition() const{
+PageTransition::Type LocationBarViewGtk::GetPageTransition() const {
return transition_;
}
-void LocationBarViewGtk::AcceptInput(){
- NOTIMPLEMENTED();
+void LocationBarViewGtk::AcceptInput() {
+ location_entry_->model()->AcceptInput(CURRENT_TAB, false);
}
-void LocationBarViewGtk::FocusLocation(){
- edit_view_->FocusLocation();
+void LocationBarViewGtk::FocusLocation() {
+ location_entry_->SetFocus();
+ location_entry_->SelectAll(true);
}
-void LocationBarViewGtk::FocusSearch(){
- NOTIMPLEMENTED();
+void LocationBarViewGtk::FocusSearch() {
+ location_entry_->SetUserText(L"?");
+ location_entry_->SetFocus();
}
-void LocationBarViewGtk::SaveStateToContents(TabContents* contents){
+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
index 50b0775..67c8fdc 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -65,7 +65,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
private:
GtkWidget* vbox_;
- scoped_ptr<AutocompleteEditViewGtk> edit_view_;
+ scoped_ptr<AutocompleteEditViewGtk> location_entry_;
Profile* profile_;
CommandUpdater* command_updater_;