summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-06 23:01:58 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-06 23:01:58 +0000
commitc588b7ffe21fffd49328a2b44edf903a8af843f3 (patch)
treeadbda99f1d54d28db340a176f2988318bba1e418 /chrome/browser/autocomplete
parentb53ab229bdba6cd50585c8fcaad011998b02f82c (diff)
downloadchromium_src-c588b7ffe21fffd49328a2b44edf903a8af843f3.zip
chromium_src-c588b7ffe21fffd49328a2b44edf903a8af843f3.tar.gz
chromium_src-c588b7ffe21fffd49328a2b44edf903a8af843f3.tar.bz2
[gtk] Add fade-commit to instant suggestion for predictive instant.
BUG=65399 TEST=manual Review URL: http://codereview.chromium.org/5588004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68395 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc90
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h17
2 files changed, 99 insertions, 8 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 6346eca..9814a59 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -10,6 +10,7 @@
#include <algorithm>
#include "app/l10n_util.h"
+#include "app/multi_animation.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -22,10 +23,12 @@
#include "chrome/browser/defaults.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/gtk/view_id_util.h"
+#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/common/notification_service.h"
+#include "gfx/color_utils.h"
#include "gfx/font.h"
#include "gfx/gtk_util.h"
#include "gfx/skia_utils_gtk.h"
@@ -336,6 +339,7 @@ void AutocompleteEditViewGtk::Init() {
// GtkLabel is used instead of GtkTextView to get transparent background.
instant_view_ = gtk_label_new(NULL);
gtk_widget_set_no_show_all(instant_view_, TRUE);
+ gtk_label_set_selectable(GTK_LABEL(instant_view_), TRUE);
GtkTextIter end_iter;
gtk_text_buffer_get_end_iter(text_buffer_, &end_iter);
@@ -372,6 +376,14 @@ void AutocompleteEditViewGtk::Init() {
AdjustVerticalAlignmentOfInstantView();
+ MultiAnimation::Parts parts;
+ parts.push_back(MultiAnimation::Part(
+ InstantController::kAutoCommitPauseTimeMS, Tween::ZERO));
+ parts.push_back(MultiAnimation::Part(
+ InstantController::kAutoCommitFadeInTimeMS, Tween::EASE_IN));
+ instant_animation_.reset(new MultiAnimation(parts));
+ instant_animation_->set_continuous(false);
+
#if !defined(TOOLKIT_VIEWS)
registrar_.Add(this,
NotificationType::BROWSER_THEME_CHANGED,
@@ -740,6 +752,18 @@ void AutocompleteEditViewGtk::Observe(NotificationType type,
SetBaseColor();
}
+void AutocompleteEditViewGtk::AnimationEnded(const Animation* animation) {
+ controller_->OnCommitSuggestedText(GetText());
+}
+
+void AutocompleteEditViewGtk::AnimationProgressed(const Animation* animation) {
+ UpdateInstantViewColors();
+}
+
+void AutocompleteEditViewGtk::AnimationCanceled(const Animation* animation) {
+ UpdateInstantViewColors();
+}
+
void AutocompleteEditViewGtk::SetBaseColor() {
#if defined(TOOLKIT_VIEWS)
bool use_gtk = false;
@@ -769,9 +793,6 @@ void AutocompleteEditViewGtk::SetBaseColor() {
g_object_set(faded_text_tag_, "foreground-gdk", &average_color, NULL);
g_object_set(normal_text_tag_, "foreground-gdk",
&style->text[GTK_STATE_NORMAL], NULL);
-
- // GtkLabel uses fg color instead of text color.
- gtk_widget_modify_fg(instant_view_, GTK_STATE_NORMAL, &average_color);
} else {
const GdkColor* background_color_ptr;
#if defined(TOOLKIT_VIEWS)
@@ -786,8 +807,8 @@ void AutocompleteEditViewGtk::SetBaseColor() {
text_view_, &gtk_util::kGdkBlack, &gtk_util::kGdkGray);
gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, background_color_ptr);
- GdkColor c;
#if !defined(TOOLKIT_VIEWS)
+ GdkColor c;
// Override the selected colors so we don't leak colors from the current
// gtk theme into the chrome-theme.
c = gfx::SkColorToGdkColor(
@@ -807,9 +828,6 @@ void AutocompleteEditViewGtk::SetBaseColor() {
gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, &c);
#endif
- gdk_color_parse(kTextBaseColor, &c);
- gtk_widget_modify_fg(instant_view_, GTK_STATE_NORMAL, &c);
-
// Until we switch to vector graphics, force the font size.
gtk_util::ForceFontSizePixels(text_view_,
popup_window_mode_ ?
@@ -826,6 +844,50 @@ void AutocompleteEditViewGtk::SetBaseColor() {
}
AdjustVerticalAlignmentOfInstantView();
+ UpdateInstantViewColors();
+}
+
+void AutocompleteEditViewGtk::UpdateInstantViewColors() {
+#if !defined(TOOLKIT_VIEWS)
+ SkColor selection_text, selection_bg;
+ GdkColor faded_text, normal_bg;
+
+ if (theme_provider_->UseGtkTheme()) {
+ GtkStyle* style = gtk_rc_get_style(text_view_);
+
+ faded_text = gtk_util::AverageColors(
+ style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]);
+ normal_bg = style->base[GTK_STATE_NORMAL];
+
+ selection_text = gfx::GdkColorToSkColor(style->text[GTK_STATE_SELECTED]);
+ selection_bg = gfx::GdkColorToSkColor(style->base[GTK_STATE_SELECTED]);
+ } else {
+ gdk_color_parse(kTextBaseColor, &faded_text);
+ normal_bg = LocationBarViewGtk::kBackgroundColor;
+
+ selection_text =
+ theme_provider_->get_active_selection_fg_color();
+ selection_bg =
+ theme_provider_->get_active_selection_bg_color();
+ }
+
+ double alpha = instant_animation_->GetCurrentValue();
+ GdkColor text = gfx::SkColorToGdkColor(color_utils::AlphaBlend(
+ selection_text,
+ gfx::GdkColorToSkColor(faded_text),
+ alpha * 0xff));
+ GdkColor bg = gfx::SkColorToGdkColor(color_utils::AlphaBlend(
+ selection_bg,
+ gfx::GdkColorToSkColor(normal_bg),
+ alpha * 0xff));
+
+ // ACTIVE is the state for text that is selected, but not focused (the
+ // instant view is always fully selected and never has focus).
+ gtk_widget_modify_text(instant_view_, GTK_STATE_ACTIVE, &text);
+ gtk_widget_modify_base(instant_view_, GTK_STATE_ACTIVE, &bg);
+#else // defined(TOOLKIT_VIEWS)
+ // We don't worry about views because it doesn't use the instant view.
+#endif
}
void AutocompleteEditViewGtk::HandleBeginUserAction(GtkTextBuffer* sender) {
@@ -1697,11 +1759,25 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() {
void AutocompleteEditViewGtk::SetInstantSuggestion(
const std::string& suggestion) {
gtk_label_set_text(GTK_LABEL(instant_view_), suggestion.c_str());
+ // Select the whole thing.
+ gtk_label_select_region(GTK_LABEL(instant_view_), 0, -1);
+
+ // Clear the animation delegate so we don't get an AnimationEnded() callback.
+ instant_animation_->set_delegate(NULL);
+ instant_animation_->Stop();
+
if (suggestion.empty()) {
gtk_widget_hide(instant_view_);
} else {
+ if (InstantController::IsEnabled(model_->profile(),
+ InstantController::PREDICTIVE_TYPE)) {
+ instant_animation_->set_delegate(this);
+ instant_animation_->Start();
+ }
+
gtk_widget_show(instant_view_);
AdjustVerticalAlignmentOfInstantView();
+ UpdateInstantViewColors();
}
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index feee937..fa25e90 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -11,6 +11,7 @@
#include <algorithm>
#include <string>
+#include "app/animation_delegate.h"
#include "app/gtk_signal.h"
#include "app/gtk_signal_registrar.h"
#include "base/basictypes.h"
@@ -28,6 +29,7 @@
class AutocompleteEditController;
class AutocompleteEditModel;
class AutocompletePopupView;
+class MultiAnimation;
class Profile;
class TabContents;
@@ -44,7 +46,8 @@ class GtkThemeProvider;
#endif
class AutocompleteEditViewGtk : public AutocompleteEditView,
- public NotificationObserver {
+ public NotificationObserver,
+ public AnimationDelegate {
public:
// Modeled like the Windows CHARRANGE. Represent a pair of cursor position
// offsets. Since GtkTextIters are invalid after the buffer is changed, we
@@ -146,7 +149,16 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
const NotificationSource& source,
const NotificationDetails& details);
+ // Overridden from AnimationDelegate.
+ virtual void AnimationEnded(const Animation* animation);
+ virtual void AnimationProgressed(const Animation* animation);
+ virtual void AnimationCanceled(const Animation* animation);
+
+ // Sets the colors of the text view according to the theme.
void SetBaseColor();
+ // Sets the colors of the instant suggestion view according to the theme and
+ // the animation state.
+ void UpdateInstantViewColors();
void SetInstantSuggestion(const std::string& suggestion);
bool CommitInstantSuggestion();
@@ -349,6 +361,9 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
// A widget for displaying instant suggestion text. It'll be attached to a
// child anchor in the |text_buffer_| object.
GtkWidget* instant_view_;
+ // Animation from instant suggest (faded text) to autocomplete (selected
+ // text).
+ scoped_ptr<MultiAnimation> instant_animation_;
// A mark to split the content and the instant anchor. Wherever the end
// iterator of the text buffer is required, the iterator to this mark should