summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-31 15:23:52 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-31 15:23:52 +0000
commit9eb8f98b6f7582ce25ba8cac11827edb8a08a5eb (patch)
tree414144c1f93e2a4534a8ad7e763f30edb6242d6a /chrome
parent00f17cfe1032061d8802db44639f3be62294b474 (diff)
downloadchromium_src-9eb8f98b6f7582ce25ba8cac11827edb8a08a5eb.zip
chromium_src-9eb8f98b6f7582ce25ba8cac11827edb8a08a5eb.tar.gz
chromium_src-9eb8f98b6f7582ce25ba8cac11827edb8a08a5eb.tar.bz2
Linux: Re-enable omnibox select-all-on-click for Chrome OS builds.
TEST=built chrome-os and non- binaries and made sure they worked as expected Review URL: http://codereview.chromium.org/342069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc78
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h23
2 files changed, 101 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index fd13ee1..64832f02 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -103,6 +103,11 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
popup_window_mode_(popup_window_mode),
scheme_security_level_(ToolbarModel::NORMAL),
mark_set_handler_id_(0),
+#if defined(OS_CHROMEOS)
+ button_1_pressed_(false),
+ text_selected_during_click_(false),
+ text_view_focused_before_button_press_(false),
+#endif
#if !defined(TOOLKIT_VIEWS)
theme_provider_(GtkThemeProvider::GetFrom(profile)),
#endif
@@ -189,6 +194,12 @@ void AutocompleteEditViewGtk::Init() {
G_CALLBACK(&HandleKeyPressThunk), this);
g_signal_connect(text_view_, "key-release-event",
G_CALLBACK(&HandleKeyReleaseThunk), this);
+#if defined(OS_CHROMEOS)
+ g_signal_connect(text_view_, "button-press-event",
+ G_CALLBACK(&HandleViewButtonPressThunk), this);
+ g_signal_connect(text_view_, "button-release-event",
+ G_CALLBACK(&HandleViewButtonReleaseThunk), this);
+#endif
g_signal_connect(text_view_, "focus-in-event",
G_CALLBACK(&HandleViewFocusInThunk), this);
g_signal_connect(text_view_, "focus-out-event",
@@ -715,6 +726,65 @@ gboolean AutocompleteEditViewGtk::HandleKeyRelease(GtkWidget* widget,
return FALSE; // Propagate into GtkTextView.
}
+#if defined(OS_CHROMEOS)
+gboolean AutocompleteEditViewGtk::HandleViewButtonPress(GdkEventButton* event) {
+ // We don't need to care about double and triple clicks.
+ if (event->type != GDK_BUTTON_PRESS)
+ return FALSE;
+
+ if (event->button == 1) {
+ // When the first button is pressed, track some stuff that will help us
+ // determine whether we should select all of the text when the button is
+ // released.
+ button_1_pressed_ = true;
+ text_view_focused_before_button_press_ = GTK_WIDGET_HAS_FOCUS(text_view_);
+ text_selected_during_click_ = false;
+
+ // Button press event may change the selection, we need to record the change
+ // and report it to |model_| later when button is released.
+ OnBeforePossibleChange();
+ } else if (event->button == 2) {
+ // GtkTextView pastes PRIMARY selection with middle click.
+ // We can't call model_->on_paste_replacing_all() here, because the actual
+ // paste clipboard action may not be performed if the clipboard is empty.
+ paste_clipboard_requested_ = true;
+ }
+ return FALSE;
+}
+
+gboolean AutocompleteEditViewGtk::HandleViewButtonRelease(
+ GdkEventButton* event) {
+ if (event->button != 1)
+ return FALSE;
+
+ button_1_pressed_ = false;
+
+ // Call the GtkTextView default handler, ignoring the fact that it will
+ // likely have told us to stop propagating. We want to handle selection.
+ GtkWidgetClass* klass = GTK_WIDGET_GET_CLASS(text_view_);
+ klass->button_release_event(text_view_, event);
+
+ if (!text_view_focused_before_button_press_ && !text_selected_during_click_) {
+ // If this was a focusing click and the user didn't drag to highlight any
+ // text, select the full input and update the PRIMARY selection.
+ SelectAllInternal(false, true);
+
+ // So we told the buffer where the cursor should be, but make sure to tell
+ // the view so it can scroll it to be visible if needed.
+ // NOTE: This function doesn't seem to like a count of 0, looking at the
+ // code it will skip an important loop. Use -1 to achieve the same.
+ GtkTextIter start, end;
+ gtk_text_buffer_get_bounds(text_buffer_, &start, &end);
+ gtk_text_view_move_visually(GTK_TEXT_VIEW(text_view_), &start, -1);
+ }
+
+ // Inform |model_| about possible text selection change.
+ OnAfterPossibleChange();
+
+ return TRUE; // Don't continue, we called the default handler already.
+}
+#endif
+
gboolean AutocompleteEditViewGtk::HandleViewFocusIn() {
GdkModifierType modifiers;
gdk_window_get_pointer(text_view_->window, NULL, NULL, &modifiers);
@@ -852,6 +922,14 @@ void AutocompleteEditViewGtk::HandleMarkSet(GtkTextBuffer* buffer,
g_free(text);
}
+#if defined(OS_CHROMEOS)
+ // If the user just selected some text with the mouse (or at least while the
+ // mouse button was down), make sure that we won't blow their selection away
+ // later by selecting all of the text when the button is released.
+ if (button_1_pressed_ && !new_selected_text.empty())
+ text_selected_during_click_ = true;
+#endif
+
// If we had some text selected earlier but it's no longer highlighted, we
// might need to save it now...
if (!selected_text_.empty() && new_selected_text.empty()) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index adef44c..cbf4965 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -147,6 +147,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
}
gboolean HandleKeyRelease(GtkWidget* widget, GdkEventKey* event);
+#if defined(OS_CHROMEOS)
static gboolean HandleViewButtonPressThunk(GtkWidget* view,
GdkEventButton* event,
gpointer self) {
@@ -162,6 +163,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
HandleViewButtonRelease(event);
}
gboolean HandleViewButtonRelease(GdkEventButton* event);
+#endif
static gboolean HandleViewFocusInThunk(GtkWidget* view,
GdkEventFocus* event,
@@ -383,6 +385,27 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
// ID of the signal handler for "mark-set" on |text_buffer_|.
gulong mark_set_handler_id_;
+#if defined(OS_CHROMEOS)
+ // The following variables are used to implement select-all-on-mouse-up, which
+ // is disabled in the standard Linux build due to poor interaction with the
+ // PRIMARY X selection.
+
+ // Is the first mouse button currently down? When selection marks get moved,
+ // we use this to determine if the user was highlighting text with the mouse
+ // -- if so, we avoid selecting all the text on mouse-up.
+ bool button_1_pressed_;
+
+ // Did the user change the selected text in the middle of the current click?
+ // If so, we don't select all of the text when the button is released -- we
+ // don't want to blow away their selection.
+ bool text_selected_during_click_;
+
+ // Was the text view already focused before the user clicked in it? We use
+ // this to figure out whether we should select all of the text when the button
+ // is released (we only do so if the view was initially unfocused).
+ bool text_view_focused_before_button_press_;
+#endif
+
#if !defined(TOOLKIT_VIEWS)
// Supplies colors, et cetera.
GtkThemeProvider* theme_provider_;