OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 #include "ui/views/ime/input_method.h" | 53 #include "ui/views/ime/input_method.h" |
54 #include "ui/views/layout/fill_layout.h" | 54 #include "ui/views/layout/fill_layout.h" |
55 #include "ui/views/views_delegate.h" | 55 #include "ui/views/views_delegate.h" |
56 #include "ui/views/widget/widget.h" | 56 #include "ui/views/widget/widget.h" |
57 #include "url/gurl.h" | 57 #include "url/gurl.h" |
58 | 58 |
59 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
60 #include "chrome/browser/browser_process.h" | 60 #include "chrome/browser/browser_process.h" |
61 #endif | 61 #endif |
62 | 62 |
63 | |
63 namespace { | 64 namespace { |
64 | 65 |
66 // OmniboxState --------------------------------------------------------------- | |
67 | |
65 // Stores omnibox state for each tab. | 68 // Stores omnibox state for each tab. |
66 struct OmniboxState : public base::SupportsUserData::Data { | 69 struct OmniboxState : public base::SupportsUserData::Data { |
67 static const char kKey[]; | 70 static const char kKey[]; |
68 | 71 |
69 OmniboxState(const OmniboxEditModel::State& model_state, | 72 OmniboxState(const OmniboxEditModel::State& model_state, |
70 const gfx::Range& selection, | 73 const gfx::Range& selection, |
71 const gfx::Range& saved_selection_for_focus_change); | 74 const gfx::Range& saved_selection_for_focus_change); |
72 virtual ~OmniboxState(); | 75 virtual ~OmniboxState(); |
73 | 76 |
74 const OmniboxEditModel::State model_state; | 77 const OmniboxEditModel::State model_state; |
(...skipping 10 matching lines...) Expand all Loading... | |
85 const char OmniboxState::kKey[] = "OmniboxState"; | 88 const char OmniboxState::kKey[] = "OmniboxState"; |
86 | 89 |
87 OmniboxState::OmniboxState(const OmniboxEditModel::State& model_state, | 90 OmniboxState::OmniboxState(const OmniboxEditModel::State& model_state, |
88 const gfx::Range& selection, | 91 const gfx::Range& selection, |
89 const gfx::Range& saved_selection_for_focus_change) | 92 const gfx::Range& saved_selection_for_focus_change) |
90 : model_state(model_state), | 93 : model_state(model_state), |
91 selection(selection), | 94 selection(selection), |
92 saved_selection_for_focus_change(saved_selection_for_focus_change) { | 95 saved_selection_for_focus_change(saved_selection_for_focus_change) { |
93 } | 96 } |
94 | 97 |
95 OmniboxState::~OmniboxState() {} | 98 OmniboxState::~OmniboxState() { |
99 } | |
100 | |
101 | |
102 // Helpers -------------------------------------------------------------------- | |
96 | 103 |
97 // We'd like to set the text input type to TEXT_INPUT_TYPE_URL, because this | 104 // We'd like to set the text input type to TEXT_INPUT_TYPE_URL, because this |
98 // triggers URL-specific layout in software keyboards, e.g. adding top-level "/" | 105 // triggers URL-specific layout in software keyboards, e.g. adding top-level "/" |
99 // and ".com" keys for English. However, this also causes IMEs to default to | 106 // and ".com" keys for English. However, this also causes IMEs to default to |
100 // Latin character mode, which makes entering search queries difficult for IME | 107 // Latin character mode, which makes entering search queries difficult for IME |
101 // users. Therefore, we try to guess whether an IME will be used based on the | 108 // users. Therefore, we try to guess whether an IME will be used based on the |
102 // application language, and set the input type accordingly. | 109 // application language, and set the input type accordingly. |
103 ui::TextInputType DetermineTextInputType() { | 110 ui::TextInputType DetermineTextInputType() { |
104 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
105 DCHECK(g_browser_process); | 112 DCHECK(g_browser_process); |
106 const std::string& locale = g_browser_process->GetApplicationLocale(); | 113 const std::string& locale = g_browser_process->GetApplicationLocale(); |
107 const std::string& language = locale.substr(0, 2); | 114 const std::string& language = locale.substr(0, 2); |
108 // Assume CJK + Thai users are using an IME. | 115 // Assume CJK + Thai users are using an IME. |
109 if (language == "ja" || | 116 if (language == "ja" || |
110 language == "ko" || | 117 language == "ko" || |
111 language == "th" || | 118 language == "th" || |
112 language == "zh") | 119 language == "zh") |
113 return ui::TEXT_INPUT_TYPE_SEARCH; | 120 return ui::TEXT_INPUT_TYPE_SEARCH; |
114 #endif | 121 #endif |
115 return ui::TEXT_INPUT_TYPE_URL; | 122 return ui::TEXT_INPUT_TYPE_URL; |
116 } | 123 } |
117 | 124 |
118 } // namespace | 125 } // namespace |
119 | 126 |
127 | |
128 // OmniboxViewViews ----------------------------------------------------------- | |
129 | |
120 // static | 130 // static |
121 const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews"; | 131 const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews"; |
122 | 132 |
123 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, | 133 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, |
124 Profile* profile, | 134 Profile* profile, |
125 CommandUpdater* command_updater, | 135 CommandUpdater* command_updater, |
126 bool popup_window_mode, | 136 bool popup_window_mode, |
127 LocationBarView* location_bar, | 137 LocationBarView* location_bar, |
128 const gfx::FontList& font_list) | 138 const gfx::FontList& font_list) |
129 : OmniboxView(profile, controller, command_updater), | 139 : OmniboxView(profile, controller, command_updater), |
(...skipping 15 matching lines...) Expand all Loading... | |
145 #if defined(OS_CHROMEOS) | 155 #if defined(OS_CHROMEOS) |
146 chromeos::input_method::InputMethodManager::Get()-> | 156 chromeos::input_method::InputMethodManager::Get()-> |
147 RemoveCandidateWindowObserver(this); | 157 RemoveCandidateWindowObserver(this); |
148 #endif | 158 #endif |
149 | 159 |
150 // Explicitly teardown members which have a reference to us. Just to be safe | 160 // Explicitly teardown members which have a reference to us. Just to be safe |
151 // we want them to be destroyed before destroying any other internal state. | 161 // we want them to be destroyed before destroying any other internal state. |
152 popup_view_.reset(); | 162 popup_view_.reset(); |
153 } | 163 } |
154 | 164 |
155 //////////////////////////////////////////////////////////////////////////////// | |
156 // OmniboxViewViews public: | |
157 | |
158 void OmniboxViewViews::Init() { | 165 void OmniboxViewViews::Init() { |
159 set_controller(this); | 166 set_controller(this); |
160 SetTextInputType(DetermineTextInputType()); | 167 SetTextInputType(DetermineTextInputType()); |
161 | 168 |
162 if (popup_window_mode_) | 169 if (popup_window_mode_) |
163 SetReadOnly(true); | 170 SetReadOnly(true); |
164 | 171 |
165 // Initialize the popup view using the same font. | 172 // Initialize the popup view using the same font. |
166 popup_view_.reset(OmniboxPopupContentsView::Create( | 173 popup_view_.reset(OmniboxPopupContentsView::Create( |
167 GetFontList(), this, model(), location_bar_view_)); | 174 GetFontList(), this, model(), location_bar_view_)); |
168 | 175 |
169 #if defined(OS_CHROMEOS) | 176 #if defined(OS_CHROMEOS) |
170 chromeos::input_method::InputMethodManager::Get()-> | 177 chromeos::input_method::InputMethodManager::Get()-> |
171 AddCandidateWindowObserver(this); | 178 AddCandidateWindowObserver(this); |
172 #endif | 179 #endif |
173 | 180 |
174 fade_in_animation_.reset(new gfx::SlideAnimation(this)); | 181 fade_in_animation_.reset(new gfx::SlideAnimation(this)); |
175 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); | 182 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); |
176 fade_in_animation_->SetSlideDuration(300); | 183 fade_in_animation_->SetSlideDuration(300); |
177 } | 184 } |
178 | 185 |
179 void OmniboxViewViews::FadeIn() { | 186 void OmniboxViewViews::FadeIn() { |
180 fade_in_animation_->Show(); | 187 fade_in_animation_->Show(); |
181 } | 188 } |
182 | 189 |
183 //////////////////////////////////////////////////////////////////////////////// | |
184 // OmniboxViewViews, public OmniboxView implementation: | |
185 | |
186 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) { | 190 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) { |
187 DCHECK(tab); | 191 DCHECK(tab); |
188 | 192 |
189 // We don't want to keep the IME status, so force quit the current | 193 // We don't want to keep the IME status, so force quit the current |
190 // session here. It may affect the selection status, so order is | 194 // session here. It may affect the selection status, so order is |
191 // also important. | 195 // also important. |
192 if (IsIMEComposing()) { | 196 if (IsIMEComposing()) { |
193 GetTextInputClient()->ConfirmCompositionText(); | 197 GetTextInputClient()->ConfirmCompositionText(); |
194 GetInputMethod()->CancelComposition(this); | 198 GetInputMethod()->CancelComposition(this); |
195 } | 199 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 int OmniboxViewViews::GetTextWidth() const { | 312 int OmniboxViewViews::GetTextWidth() const { |
309 // Returns the width necessary to display the current text, including any | 313 // Returns the width necessary to display the current text, including any |
310 // necessary space for the cursor or border/margin. | 314 // necessary space for the cursor or border/margin. |
311 return GetRenderText()->GetContentWidth() + GetInsets().width(); | 315 return GetRenderText()->GetContentWidth() + GetInsets().width(); |
312 } | 316 } |
313 | 317 |
314 bool OmniboxViewViews::IsImeComposing() const { | 318 bool OmniboxViewViews::IsImeComposing() const { |
315 return IsIMEComposing(); | 319 return IsIMEComposing(); |
316 } | 320 } |
317 | 321 |
322 gfx::Size OmniboxViewViews::GetMinimumSize() { | |
323 const int kMinCharacters = 10; | |
324 return gfx::Size( | |
325 GetFontList().GetExpectedTextWidth(kMinCharacters) + GetInsets.width(), | |
326 GetPreferredSize().height()); | |
327 } | |
328 | |
329 void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
330 views::Textfield::OnNativeThemeChanged(theme); | |
331 SetBackgroundColor(location_bar_view_->GetColor( | |
332 ToolbarModel::NONE, LocationBarView::BACKGROUND)); | |
333 EmphasizeURLComponents(); | |
334 } | |
335 | |
318 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { | 336 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { |
319 switch (command_id) { | 337 switch (command_id) { |
320 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). | 338 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). |
321 case IDS_PASTE_AND_GO: | 339 case IDS_PASTE_AND_GO: |
322 model()->PasteAndGo(GetClipboardText()); | 340 model()->PasteAndGo(GetClipboardText()); |
323 break; | 341 break; |
324 case IDS_SHOW_URL: | 342 case IDS_SHOW_URL: |
325 controller()->ShowURL(); | 343 controller()->ShowURL(); |
326 break; | 344 break; |
327 case IDC_EDIT_SEARCH_ENGINES: | 345 case IDC_EDIT_SEARCH_ENGINES: |
(...skipping 10 matching lines...) Expand all Loading... | |
338 OnPaste(); | 356 OnPaste(); |
339 else if (Textfield::IsCommandIdEnabled(command_id)) | 357 else if (Textfield::IsCommandIdEnabled(command_id)) |
340 Textfield::ExecuteCommand(command_id, event_flags); | 358 Textfield::ExecuteCommand(command_id, event_flags); |
341 else | 359 else |
342 command_updater()->ExecuteCommand(command_id); | 360 command_updater()->ExecuteCommand(command_id); |
343 OnAfterPossibleChange(); | 361 OnAfterPossibleChange(); |
344 break; | 362 break; |
345 } | 363 } |
346 } | 364 } |
347 | 365 |
348 //////////////////////////////////////////////////////////////////////////////// | |
349 // OmniboxViewViews, private: | |
350 | |
351 int OmniboxViewViews::GetOmniboxTextLength() const { | |
352 // TODO(oshima): Support IME. | |
353 return static_cast<int>(text().length()); | |
354 } | |
355 | |
356 void OmniboxViewViews::EmphasizeURLComponents() { | |
357 // See whether the contents are a URL with a non-empty host portion, which we | |
358 // should emphasize. To check for a URL, rather than using the type returned | |
359 // by Parse(), ask the model, which will check the desired page transition for | |
360 // this input. This can tell us whether an UNKNOWN input string is going to | |
361 // be treated as a search or a navigation, and is the same method the Paste | |
362 // And Go system uses. | |
363 url::Component scheme, host; | |
364 AutocompleteInput::ParseForEmphasizeComponents(text(), &scheme, &host); | |
365 bool grey_out_url = text().substr(scheme.begin, scheme.len) == | |
366 base::UTF8ToUTF16(extensions::kExtensionScheme); | |
367 bool grey_base = model()->CurrentTextIsURL() && | |
368 (host.is_nonempty() || grey_out_url); | |
369 SetColor(location_bar_view_->GetColor( | |
370 security_level_, | |
371 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | |
372 if (grey_base && !grey_out_url) { | |
373 ApplyColor( | |
374 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT), | |
375 gfx::Range(host.begin, host.end())); | |
376 } | |
377 | |
378 // Emphasize the scheme for security UI display purposes (if necessary). | |
379 // Note that we check CurrentTextIsURL() because if we're replacing search | |
380 // URLs with search terms, we may have a non-URL even when the user is not | |
381 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | |
382 // may have incorrectly identified a qualifier as a scheme. | |
383 SetStyle(gfx::DIAGONAL_STRIKE, false); | |
384 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | |
385 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | |
386 SkColor security_color = location_bar_view_->GetColor( | |
387 security_level_, LocationBarView::SECURITY_TEXT); | |
388 const bool strike = (security_level_ == ToolbarModel::SECURITY_ERROR); | |
389 const gfx::Range scheme_range(scheme.begin, scheme.end()); | |
390 ApplyColor(security_color, scheme_range); | |
391 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | |
392 } | |
393 } | |
394 | |
395 void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text, | 366 void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text, |
Greg Billock
2014/05/13 16:08:15
These are all just re-ordered, right?
Peter Kasting
2014/05/13 20:50:14
Yes. The only functional change is the addition o
| |
396 const gfx::Range& range) { | 367 const gfx::Range& range) { |
397 SetText(text); | 368 SetText(text); |
398 SelectRange(range); | 369 SelectRange(range); |
399 } | 370 } |
400 | 371 |
401 base::string16 OmniboxViewViews::GetSelectedText() const { | 372 base::string16 OmniboxViewViews::GetSelectedText() const { |
402 // TODO(oshima): Support IME. | 373 // TODO(oshima): Support IME. |
403 return views::Textfield::GetSelectedText(); | 374 return views::Textfield::GetSelectedText(); |
404 } | 375 } |
405 | 376 |
(...skipping 25 matching lines...) Expand all Loading... | |
431 } else { | 402 } else { |
432 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); | 403 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); |
433 } | 404 } |
434 return true; | 405 return true; |
435 } | 406 } |
436 } | 407 } |
437 | 408 |
438 return false; | 409 return false; |
439 } | 410 } |
440 | 411 |
441 //////////////////////////////////////////////////////////////////////////////// | |
442 // OmniboxViewViews, private View implementation: | |
443 | |
444 void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
445 views::Textfield::OnNativeThemeChanged(theme); | |
446 SetBackgroundColor(location_bar_view_->GetColor( | |
447 ToolbarModel::NONE, LocationBarView::BACKGROUND)); | |
448 EmphasizeURLComponents(); | |
449 } | |
450 | |
451 //////////////////////////////////////////////////////////////////////////////// | |
452 // OmniboxViewViews, private OmniboxView implementation: | |
453 | |
454 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, | 412 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, |
455 size_t caret_pos, | 413 size_t caret_pos, |
456 bool update_popup, | 414 bool update_popup, |
457 bool notify_text_changed) { | 415 bool notify_text_changed) { |
458 const gfx::Range range(caret_pos, caret_pos); | 416 const gfx::Range range(caret_pos, caret_pos); |
459 SetTextAndSelectedRange(text, range); | 417 SetTextAndSelectedRange(text, range); |
460 | 418 |
461 if (update_popup) | 419 if (update_popup) |
462 UpdatePopup(); | 420 UpdatePopup(); |
463 | 421 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 GetInputMethod()->ShowImeIfNeeded(); | 564 GetInputMethod()->ShowImeIfNeeded(); |
607 } | 565 } |
608 | 566 |
609 void OmniboxViewViews::OnMatchOpened(const AutocompleteMatch& match, | 567 void OmniboxViewViews::OnMatchOpened(const AutocompleteMatch& match, |
610 Profile* profile, | 568 Profile* profile, |
611 content::WebContents* web_contents) const { | 569 content::WebContents* web_contents) const { |
612 extensions::MaybeShowExtensionControlledSearchNotification( | 570 extensions::MaybeShowExtensionControlledSearchNotification( |
613 profile, web_contents, match); | 571 profile, web_contents, match); |
614 } | 572 } |
615 | 573 |
616 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | 574 int OmniboxViewViews::GetOmniboxTextLength() const { |
617 if (command_id == IDS_APP_PASTE) | 575 // TODO(oshima): Support IME. |
618 return !read_only() && !GetClipboardText().empty(); | 576 return static_cast<int>(text().length()); |
619 if (command_id == IDS_PASTE_AND_GO) | 577 } |
620 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); | 578 |
621 if (command_id == IDS_SHOW_URL) | 579 void OmniboxViewViews::EmphasizeURLComponents() { |
622 return controller()->GetToolbarModel()->WouldReplaceURL(); | 580 // See whether the contents are a URL with a non-empty host portion, which we |
623 return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP || | 581 // should emphasize. To check for a URL, rather than using the type returned |
624 Textfield::IsCommandIdEnabled(command_id) || | 582 // by Parse(), ask the model, which will check the desired page transition for |
625 command_updater()->IsCommandEnabled(command_id); | 583 // this input. This can tell us whether an UNKNOWN input string is going to |
584 // be treated as a search or a navigation, and is the same method the Paste | |
585 // And Go system uses. | |
586 url::Component scheme, host; | |
587 AutocompleteInput::ParseForEmphasizeComponents(text(), &scheme, &host); | |
588 bool grey_out_url = text().substr(scheme.begin, scheme.len) == | |
589 base::UTF8ToUTF16(extensions::kExtensionScheme); | |
590 bool grey_base = model()->CurrentTextIsURL() && | |
591 (host.is_nonempty() || grey_out_url); | |
592 SetColor(location_bar_view_->GetColor( | |
593 security_level_, | |
594 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | |
595 if (grey_base && !grey_out_url) { | |
596 ApplyColor( | |
597 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT), | |
598 gfx::Range(host.begin, host.end())); | |
599 } | |
600 | |
601 // Emphasize the scheme for security UI display purposes (if necessary). | |
602 // Note that we check CurrentTextIsURL() because if we're replacing search | |
603 // URLs with search terms, we may have a non-URL even when the user is not | |
604 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | |
605 // may have incorrectly identified a qualifier as a scheme. | |
606 SetStyle(gfx::DIAGONAL_STRIKE, false); | |
607 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | |
608 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | |
609 SkColor security_color = location_bar_view_->GetColor( | |
610 security_level_, LocationBarView::SECURITY_TEXT); | |
611 const bool strike = (security_level_ == ToolbarModel::SECURITY_ERROR); | |
612 const gfx::Range scheme_range(scheme.begin, scheme.end()); | |
613 ApplyColor(security_color, scheme_range); | |
614 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | |
615 } | |
616 } | |
617 | |
618 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { | |
619 // The omnibox contents may change while the control key is pressed. | |
620 if (event.key_code() == ui::VKEY_CONTROL) | |
621 model()->OnControlKeyChanged(false); | |
622 return views::Textfield::OnKeyReleased(event); | |
626 } | 623 } |
627 | 624 |
628 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { | 625 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { |
629 return command_id == IDS_PASTE_AND_GO; | 626 return command_id == IDS_PASTE_AND_GO; |
630 } | 627 } |
631 | 628 |
632 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { | 629 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { |
633 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); | 630 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); |
634 return l10n_util::GetStringUTF16( | 631 return l10n_util::GetStringUTF16( |
635 model()->IsPasteAndSearch(GetClipboardText()) ? | 632 model()->IsPasteAndSearch(GetClipboardText()) ? |
636 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); | 633 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); |
637 } | 634 } |
638 | 635 |
639 //////////////////////////////////////////////////////////////////////////////// | |
640 // OmniboxViewViews, private views::Textfield implementation: | |
641 | |
642 const char* OmniboxViewViews::GetClassName() const { | 636 const char* OmniboxViewViews::GetClassName() const { |
643 return kViewClassName; | 637 return kViewClassName; |
644 } | 638 } |
645 | 639 |
646 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { | |
647 if (fade_in_animation_->is_animating()) { | |
648 canvas->SaveLayerAlpha(static_cast<uint8>( | |
649 fade_in_animation_->CurrentValueBetween(0, 255))); | |
650 views::Textfield::OnPaint(canvas); | |
651 canvas->Restore(); | |
652 } else { | |
653 views::Textfield::OnPaint(canvas); | |
654 } | |
655 } | |
656 | |
657 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { | 640 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { |
658 select_all_on_mouse_release_ = | 641 select_all_on_mouse_release_ = |
659 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && | 642 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
660 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); | 643 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); |
661 if (select_all_on_mouse_release_) { | 644 if (select_all_on_mouse_release_) { |
662 // Restore caret visibility whenever the user clicks in the omnibox in a way | 645 // Restore caret visibility whenever the user clicks in the omnibox in a way |
663 // that would give it focus. We must handle this case separately here | 646 // that would give it focus. We must handle this case separately here |
664 // because if the omnibox currently has invisible focus, the mouse event | 647 // because if the omnibox currently has invisible focus, the mouse event |
665 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). | 648 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). |
666 model()->SetCaretVisibility(true); | 649 model()->SetCaretVisibility(true); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 return true; | 742 return true; |
760 } | 743 } |
761 break; | 744 break; |
762 default: | 745 default: |
763 break; | 746 break; |
764 } | 747 } |
765 | 748 |
766 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); | 749 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); |
767 } | 750 } |
768 | 751 |
769 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { | |
770 // The omnibox contents may change while the control key is pressed. | |
771 if (event.key_code() == ui::VKEY_CONTROL) | |
772 model()->OnControlKeyChanged(false); | |
773 return views::Textfield::OnKeyReleased(event); | |
774 } | |
775 | |
776 void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) { | 752 void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) { |
777 if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) { | 753 if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) { |
778 select_all_on_gesture_tap_ = true; | 754 select_all_on_gesture_tap_ = true; |
779 | 755 |
780 // If we're trying to select all on tap, invalidate any saved selection lest | 756 // If we're trying to select all on tap, invalidate any saved selection lest |
781 // restoring it fights with the "select all" action. | 757 // restoring it fights with the "select all" action. |
782 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); | 758 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); |
783 } | 759 } |
784 | 760 |
785 if (select_all_on_gesture_tap_ && event->type() == ui::ET_GESTURE_TAP) | 761 if (select_all_on_gesture_tap_ && event->type() == ui::ET_GESTURE_TAP) |
(...skipping 27 matching lines...) Expand all Loading... | |
813 return true; | 789 return true; |
814 } | 790 } |
815 return Textfield::SkipDefaultKeyEventProcessing(event); | 791 return Textfield::SkipDefaultKeyEventProcessing(event); |
816 } | 792 } |
817 | 793 |
818 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { | 794 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { |
819 location_bar_view_->GetAccessibleState(state); | 795 location_bar_view_->GetAccessibleState(state); |
820 state->role = ui::AX_ROLE_TEXT_FIELD; | 796 state->role = ui::AX_ROLE_TEXT_FIELD; |
821 } | 797 } |
822 | 798 |
799 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { | |
800 if (fade_in_animation_->is_animating()) { | |
801 canvas->SaveLayerAlpha(static_cast<uint8>( | |
802 fade_in_animation_->CurrentValueBetween(0, 255))); | |
803 views::Textfield::OnPaint(canvas); | |
804 canvas->Restore(); | |
805 } else { | |
806 views::Textfield::OnPaint(canvas); | |
807 } | |
808 } | |
809 | |
823 void OmniboxViewViews::OnFocus() { | 810 void OmniboxViewViews::OnFocus() { |
824 views::Textfield::OnFocus(); | 811 views::Textfield::OnFocus(); |
825 // TODO(oshima): Get control key state. | 812 // TODO(oshima): Get control key state. |
826 model()->OnSetFocus(false); | 813 model()->OnSetFocus(false); |
827 // Don't call controller()->OnSetFocus, this view has already acquired focus. | 814 // Don't call controller()->OnSetFocus, this view has already acquired focus. |
828 | 815 |
829 // Restore the selection we saved in OnBlur() if it's still valid. | 816 // Restore the selection we saved in OnBlur() if it's still valid. |
830 if (saved_selection_for_focus_change_.IsValid()) { | 817 if (saved_selection_for_focus_change_.IsValid()) { |
831 SelectRange(saved_selection_for_focus_change_); | 818 SelectRange(saved_selection_for_focus_change_); |
832 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); | 819 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); |
(...skipping 22 matching lines...) Expand all Loading... | |
855 | 842 |
856 // Ignore loss of focus if we lost focus because the website settings popup | 843 // Ignore loss of focus if we lost focus because the website settings popup |
857 // is open. When the popup is destroyed, focus will return to the Omnibox. | 844 // is open. When the popup is destroyed, focus will return to the Omnibox. |
858 if (!WebsiteSettingsPopupView::IsPopupShowing()) | 845 if (!WebsiteSettingsPopupView::IsPopupShowing()) |
859 OnDidKillFocus(); | 846 OnDidKillFocus(); |
860 | 847 |
861 // Make sure the beginning of the text is visible. | 848 // Make sure the beginning of the text is visible. |
862 SelectRange(gfx::Range(0)); | 849 SelectRange(gfx::Range(0)); |
863 } | 850 } |
864 | 851 |
852 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | |
853 if (command_id == IDS_APP_PASTE) | |
854 return !read_only() && !GetClipboardText().empty(); | |
855 if (command_id == IDS_PASTE_AND_GO) | |
856 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); | |
857 if (command_id == IDS_SHOW_URL) | |
858 return controller()->GetToolbarModel()->WouldReplaceURL(); | |
859 return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP || | |
860 Textfield::IsCommandIdEnabled(command_id) || | |
861 command_updater()->IsCommandEnabled(command_id); | |
862 } | |
863 | |
865 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { | 864 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { |
866 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); | 865 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); |
867 } | 866 } |
868 | 867 |
869 //////////////////////////////////////////////////////////////////////////////// | |
870 // OmniboxViewViews, private gfx::AnimationDelegate implementation: | |
871 | |
872 void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) { | 868 void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) { |
873 SchedulePaint(); | 869 SchedulePaint(); |
874 } | 870 } |
875 | 871 |
876 void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) { | 872 void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) { |
877 fade_in_animation_->Reset(); | 873 fade_in_animation_->Reset(); |
878 } | 874 } |
879 | 875 |
880 //////////////////////////////////////////////////////////////////////////////// | |
881 // OmniboxViewViews, | |
882 // chromeos::input_method::InputMethodManager::CandidateWindowObserver | |
883 // private implementation: | |
884 | |
885 #if defined(OS_CHROMEOS) | 876 #if defined(OS_CHROMEOS) |
886 void OmniboxViewViews::CandidateWindowOpened( | 877 void OmniboxViewViews::CandidateWindowOpened( |
887 chromeos::input_method::InputMethodManager* manager) { | 878 chromeos::input_method::InputMethodManager* manager) { |
888 ime_candidate_window_open_ = true; | 879 ime_candidate_window_open_ = true; |
889 } | 880 } |
890 | 881 |
891 void OmniboxViewViews::CandidateWindowClosed( | 882 void OmniboxViewViews::CandidateWindowClosed( |
892 chromeos::input_method::InputMethodManager* manager) { | 883 chromeos::input_method::InputMethodManager* manager) { |
893 ime_candidate_window_open_ = false; | 884 ime_candidate_window_open_ = false; |
894 } | 885 } |
895 #endif | 886 #endif |
896 | 887 |
897 //////////////////////////////////////////////////////////////////////////////// | |
898 // OmniboxViewViews, private views::TextfieldController implementation: | |
899 | |
900 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, | 888 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, |
901 const base::string16& new_contents) { | 889 const base::string16& new_contents) { |
902 } | 890 } |
903 | 891 |
904 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, | 892 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, |
905 const ui::KeyEvent& event) { | 893 const ui::KeyEvent& event) { |
906 delete_at_end_pressed_ = false; | 894 delete_at_end_pressed_ = false; |
907 | 895 |
908 if (event.key_code() == ui::VKEY_BACK) { | 896 if (event.key_code() == ui::VKEY_BACK) { |
909 // No extra handling is needed in keyword search mode, if there is a | 897 // No extra handling is needed in keyword search mode, if there is a |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1045 menu_contents->InsertItemWithStringIdAt( | 1033 menu_contents->InsertItemWithStringIdAt( |
1046 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1034 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
1047 } | 1035 } |
1048 | 1036 |
1049 // Minor note: We use IDC_ for command id here while the underlying textfield | 1037 // Minor note: We use IDC_ for command id here while the underlying textfield |
1050 // is using IDS_ for all its command ids. This is because views cannot depend | 1038 // is using IDS_ for all its command ids. This is because views cannot depend |
1051 // on IDC_ for now. | 1039 // on IDC_ for now. |
1052 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1040 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1053 IDS_EDIT_SEARCH_ENGINES); | 1041 IDS_EDIT_SEARCH_ENGINES); |
1054 } | 1042 } |
OLD | NEW |