diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/omnibox/omnibox_edit_model.cc | 19 | ||||
-rw-r--r-- | chrome/browser/ui/omnibox/omnibox_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/omnibox/omnibox_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.cc | 46 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.h | 11 | ||||
-rw-r--r-- | chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/views/omnibox/omnibox_view_views.cc | 32 | ||||
-rw-r--r-- | chrome/browser/ui/views/omnibox/omnibox_view_views.h | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
12 files changed, 128 insertions, 18 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 92f6af2..cf8b32f 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6829,6 +6829,12 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_ENABLE_RESET_PROFILE_SETTINGS_DESCRIPTION" desc="Description for the flag to enable a feature to reset profile settings that are often modified by malware."> Enables the option in chrome://settings to reset settings in your profile that are often modified by malware. </message> + <message name="IDS_FLAGS_ENABLE_OMNIBOX_AUTO_COMPLETION_FOR_IME_NAME" desc="Title for the flag to enable omnibox auto-completion for IMEs."> + Enable omnibox auto-completion when IME is active + </message> + <message name="IDS_FLAGS_ENABLE_OMNIBOX_AUTO_COMPLETION_FOR_IME_DESCRIPTION" desc="Description for the flag to enable auto-completion for IMEs."> + Enables omnibox auto-completion when IME is active. The auto-completion for IME is shown in the same style as the normal(non-IME) auto-completion. + </message> <message name="IDS_GENERIC_EXPERIMENT_CHOICE_AUTOMATIC" desc="Generic 'Automatic' experiment choice option name."> Automatic diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 95d6dba..ab34158 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1475,6 +1475,15 @@ const Experiment kExperiments[] = { SINGLE_VALUE_TYPE(switches::kEnableAppListShim) }, #endif +#if defined(OS_CHROMEOS) || defined(OS_WIN) + { + "enable-omnibox-auto-completion-for-ime", + IDS_FLAGS_ENABLE_OMNIBOX_AUTO_COMPLETION_FOR_IME_NAME, + IDS_FLAGS_ENABLE_OMNIBOX_AUTO_COMPLETION_FOR_IME_DESCRIPTION, + kOsCrOS, + SINGLE_VALUE_TYPE(switches::kEnableOmniboxAutoCompletionForIme) + }, +#endif }; const Experiment* experiments = kExperiments; diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index f4c7db9..0728b2f 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -230,7 +230,11 @@ void OmniboxEditModel::SetUserText(const string16& text) { void OmniboxEditModel::FinalizeInstantQuery( const string16& input_text, const InstantSuggestion& suggestion) { - if (popup_model()->IsOpen()) { + if (!popup_model()->result().empty()) { + // When a IME is active and a candidate window is open, we don't show + // the omnibox popup, though |result()| may be available. Thus we check + // whether result().empty() or not instead of whether IsOpen() or not. + // We need the finalization of instant query when result() is available. SearchProvider* search_provider = autocomplete_controller()->search_provider(); // There may be no providers during testing; guard against that. @@ -1296,12 +1300,13 @@ void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { InstantController* instant = GetInstantController(); if (instant && notify_instant) { - // Normally, popup_->ResetToDefaultMatch() will cause the view text to be - // updated. In Instant Extended mode however, the popup_ is not used, so it - // won't do anything. So, update the view ourselves. Even if Instant is not - // in extended mode (i.e., it's enabled in non-extended mode, or disabled - // altogether), this is okay to do, since the call to - // popup_->ResetToDefaultMatch() will just override whatever we do here. + // Normally, popup_model()->ResetToDefaultMatch() will cause the view text + // to be updated. In Instant Extended mode however, the popup_model() is + // not used, so it won't do anything. So, update the view ourselves. Even + // if Instant is not in extended mode (i.e., it's enabled in non-extended + // mode, or disabled altogether), this is okay to do, since the call to + // popup_model()->ResetToDefaultMatch() will just override whatever we do + // here. // // The two "false" arguments make sure that our shenanigans don't cause any // previously saved selection to be erased nor OnChanged() to be called. diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc index 2f475c4..67c8cc6 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.cc +++ b/chrome/browser/ui/omnibox/omnibox_view.cc @@ -127,6 +127,12 @@ void OmniboxView::CloseOmniboxPopup() { model_->StopAutocomplete(); } +bool OmniboxView::IsImeShowingPopup() const { + // Since not all the IMEs/platforms support the detection of a IME's popup + // window, falls back to IsImeComposing(). + return IsImeComposing(); +} + OmniboxView::OmniboxView(Profile* profile, OmniboxEditController* controller, ToolbarModel* toolbar_model, diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h index 8624c6c..b05334c 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.h +++ b/chrome/browser/ui/omnibox/omnibox_view.h @@ -209,6 +209,10 @@ class OmniboxView { // Returns true if the user is composing something in an IME. virtual bool IsImeComposing() const = 0; + // Returns true if an IME is showing a popup window, which may overlap + // the omnibox's popup window. + virtual bool IsImeShowingPopup() const; + #if defined(TOOLKIT_VIEWS) virtual int GetMaxEditWidth(int entry_width) const = 0; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index f17a5dc..a50a242 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -75,6 +75,7 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/skia_util.h" +#include "ui/views/background.h" #include "ui/views/border.h" #include "ui/views/button_drag_utils.h" #include "ui/views/controls/label.h" @@ -183,6 +184,7 @@ LocationBarView::LocationBarView(Browser* browser, location_icon_view_(NULL), ev_bubble_view_(NULL), location_entry_view_(NULL), + ime_inline_autocomplete_view_(NULL), selected_keyword_view_(NULL), suggested_text_view_(NULL), keyword_hint_view_(NULL), @@ -277,6 +279,21 @@ void LocationBarView::Init() { SetLocationEntryFocusable(true); location_entry_view_ = location_entry_->AddToView(this); + // Initialize the inline autocomplete view which is visible only when IME is + // turned on. Use the same font with the omnibox and highlighted background. + ime_inline_autocomplete_view_ = new views::Label(); + ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); + ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); + ime_inline_autocomplete_view_->set_background( + views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); + ime_inline_autocomplete_view_->SetEnabledColor( + GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TextfieldSelectionColor)); + ime_inline_autocomplete_view_->SetFont(font); + ime_inline_autocomplete_view_->SetVisible(false); + AddChildView(ime_inline_autocomplete_view_); + const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); selected_keyword_view_ = new SelectedKeywordView( bubble_font, bubble_font_y_offset, text_color, background_color, @@ -634,6 +651,11 @@ gfx::Point LocationBarView::GetLocationEntryOrigin() const { return origin; } +void LocationBarView::SetImeInlineAutocompletion(const string16& text) { + ime_inline_autocomplete_view_->SetText(text); + ime_inline_autocomplete_view_->SetVisible(!text.empty()); +} + void LocationBarView::SetInstantSuggestion(const string16& text) { if (suggested_text_view_->text() != text) { suggested_text_view_->SetText(text); @@ -892,6 +914,30 @@ void LocationBarView::Layout() { if (omnibox_views) omnibox_views->SetHorizontalMargins(0, omnibox_views_margin); + // Layout |ime_inline_autocomplete_view_| next to the user input. + if (ime_inline_autocomplete_view_->visible()) { + int width = + ime_inline_autocomplete_view_->font().GetStringWidth( + ime_inline_autocomplete_view_->text()) + + ime_inline_autocomplete_view_->GetInsets().width(); + // All the target languages (IMEs) are LTR, and we do not need to support + // RTL so far. In other words, no testable RTL environment so far. + int x; + if (width > entry_width) { + x = 0; + } else if (location_needed_width + width > entry_width) { + x = entry_width - width; + } else { + x = location_needed_width; + } + location_bounds.set_width(x); + ime_inline_autocomplete_view_->SetBounds( + location_bounds.right(), + location_bounds.y(), + std::min(width, entry_width), + location_bounds.height()); + } + location_entry_view_->SetBoundsRect(location_bounds); } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 020780c..9c8be0e 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -192,6 +192,11 @@ class LocationBarView : public LocationBar, // appears, not where the icons are shown). gfx::Point GetLocationEntryOrigin() const; + // Shows |text| as an inline autocompletion. This is useful for IMEs, where + // we can't show the autocompletion inside the actual OmniboxView. See + // comments on |ime_inline_autocomplete_view_|. + void SetImeInlineAutocompletion(const string16& text); + // Invoked from OmniboxViewWin to show the instant suggestion. void SetInstantSuggestion(const string16& text); @@ -429,6 +434,12 @@ class LocationBarView : public LocationBar, // Location_entry view views::View* location_entry_view_; + // A view to show inline autocompletion when an IME is active. In this case, + // we shouldn't change the text or selection inside the OmniboxView itself, + // since this will conflict with the IME's control over the text. So instead + // we show any autocompletion in a separate field after the OmniboxView. + views::Label* ime_inline_autocomplete_view_; + // The following views are used to provide hints and remind the user as to // what is going in the edit. They are all added a children of the // LocationBarView. At most one is visible at a time. Preference is diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc index 8474bcf..48cb593 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc @@ -162,8 +162,10 @@ void OmniboxPopupContentsView::InvalidateLine(size_t line) { } void OmniboxPopupContentsView::UpdatePopupAppearance() { - if (model_->result().empty()) { - // No matches, close any existing popup. + if (model_->result().empty() || + omnibox_view_->IsImeShowingPopup()) { + // No matches or the IME is showing a popup window which may overlap + // the omnibox popup window. Close any existing popup. if (popup_ != NULL) { size_animation_.Stop(); diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index b149ae6..545d230 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -20,6 +21,7 @@ #include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" +#include "chrome/common/chrome_switches.h" #include "content/public/browser/web_contents.h" #include "extensions/common/constants.h" #include "googleurl/src/gurl.h" @@ -432,17 +434,21 @@ void OmniboxViewViews::SelectAll(bool reversed) { void OmniboxViewViews::UpdatePopup() { model()->SetInputInProgress(true); - if (ime_candidate_window_open_) - return; if (!model()->has_focus()) return; + // Hide the inline autocompletion for IME users. + location_bar_view_->SetImeInlineAutocompletion(string16()); + // Prevent inline autocomplete when the caret isn't at the end of the text, - // and during IME composition editing. + // and during IME composition editing unless + // |kEnableOmniboxAutoCompletionForIme| is enabled. const ui::Range sel = GetSelectedRange(); model()->StartAutocomplete( !sel.is_empty(), - sel.GetMax() < text().length() || IsIMEComposing()); + sel.GetMax() < text().length() || + (IsIMEComposing() && !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableOmniboxAutoCompletionForIme))); } void OmniboxViewViews::SetFocus() { @@ -475,8 +481,14 @@ bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( size_t user_text_length) { if (display_text == text()) return false; - ui::Range range(display_text.size(), user_text_length); - SetTextAndSelectedRange(display_text, range); + + if (IsIMEComposing()) { + location_bar_view_->SetImeInlineAutocompletion( + display_text.substr(user_text_length)); + } else { + ui::Range range(display_text.size(), user_text_length); + SetTextAndSelectedRange(display_text, range); + } TextChanged(); return true; } @@ -567,7 +579,11 @@ int OmniboxViewViews::TextWidth() const { } bool OmniboxViewViews::IsImeComposing() const { - return false; + return IsIMEComposing(); +} + +bool OmniboxViewViews::IsImeShowingPopup() const { + return ime_candidate_window_open_; } int OmniboxViewViews::GetMaxEditWidth(int entry_width) const { @@ -795,13 +811,11 @@ void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { void OmniboxViewViews::CandidateWindowOpened( chromeos::input_method::InputMethodManager* manager) { ime_candidate_window_open_ = true; - CloseOmniboxPopup(); } void OmniboxViewViews::CandidateWindowClosed( chromeos::input_method::InputMethodManager* manager) { ime_candidate_window_open_ = false; - UpdatePopup(); } #endif diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.h b/chrome/browser/ui/views/omnibox/omnibox_view_views.h index 582a733..2ddf4fb 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.h @@ -104,6 +104,7 @@ class OmniboxViewViews virtual string16 GetInstantSuggestion() const OVERRIDE; virtual int TextWidth() const OVERRIDE; virtual bool IsImeComposing() const OVERRIDE; + virtual bool IsImeShowingPopup() const OVERRIDE; virtual int GetMaxEditWidth(int entry_width) const OVERRIDE; virtual views::View* AddToView(views::View* parent) OVERRIDE; virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 36112bb..117d2a9 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -615,6 +615,11 @@ const char kEnableNpn[] = "enable-npn"; // HTTP is still used for all requests. const char kEnableNpnHttpOnly[] = "enable-npn-http"; +// Enables omnibox auto-completion when IME is active. The auto-completion for +// IME is shown in the same style as the normal(non-IME) auto-completion. +const char kEnableOmniboxAutoCompletionForIme[] = + "enable-omnibox-auto-completion-for-ime"; + // Enables panels (always on-top docked pop-up windows). const char kEnablePanels[] = "enable-panels"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index efe82fa..858f5eb 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -175,6 +175,7 @@ extern const char kEnableNaClDebug[]; extern const char kEnableNetBenchmarking[]; extern const char kEnableNpn[]; extern const char kEnableNpnHttpOnly[]; +extern const char kEnableOmniboxAutoCompletionForIme[]; extern const char kEnablePanels[]; extern const char kEnablePasswordGeneration[]; extern const char kEnablePnacl[]; |