Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 200783003: [OriginChip] Add animations for the hiding and showing of the chip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to comments, merge Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 21 matching lines...) Expand all
32 #include "ui/accessibility/ax_view_state.h" 32 #include "ui/accessibility/ax_view_state.h"
33 #include "ui/base/clipboard/scoped_clipboard_writer.h" 33 #include "ui/base/clipboard/scoped_clipboard_writer.h"
34 #include "ui/base/dragdrop/drag_drop_types.h" 34 #include "ui/base/dragdrop/drag_drop_types.h"
35 #include "ui/base/dragdrop/os_exchange_data.h" 35 #include "ui/base/dragdrop/os_exchange_data.h"
36 #include "ui/base/ime/text_input_client.h" 36 #include "ui/base/ime/text_input_client.h"
37 #include "ui/base/ime/text_input_type.h" 37 #include "ui/base/ime/text_input_type.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/models/simple_menu_model.h" 39 #include "ui/base/models/simple_menu_model.h"
40 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/events/event.h" 41 #include "ui/events/event.h"
42 #include "ui/gfx/animation/slide_animation.h"
42 #include "ui/gfx/canvas.h" 43 #include "ui/gfx/canvas.h"
43 #include "ui/gfx/font_list.h" 44 #include "ui/gfx/font_list.h"
44 #include "ui/gfx/selection_model.h" 45 #include "ui/gfx/selection_model.h"
45 #include "ui/views/border.h" 46 #include "ui/views/border.h"
46 #include "ui/views/button_drag_utils.h" 47 #include "ui/views/button_drag_utils.h"
47 #include "ui/views/controls/textfield/textfield.h" 48 #include "ui/views/controls/textfield/textfield.h"
48 #include "ui/views/ime/input_method.h" 49 #include "ui/views/ime/input_method.h"
49 #include "ui/views/layout/fill_layout.h" 50 #include "ui/views/layout/fill_layout.h"
50 #include "ui/views/views_delegate.h" 51 #include "ui/views/views_delegate.h"
51 #include "ui/views/widget/widget.h" 52 #include "ui/views/widget/widget.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 SetReadOnly(true); 172 SetReadOnly(true);
172 173
173 // Initialize the popup view using the same font. 174 // Initialize the popup view using the same font.
174 popup_view_.reset(OmniboxPopupContentsView::Create( 175 popup_view_.reset(OmniboxPopupContentsView::Create(
175 GetFontList(), this, model(), location_bar_view_)); 176 GetFontList(), this, model(), location_bar_view_));
176 177
177 #if defined(OS_CHROMEOS) 178 #if defined(OS_CHROMEOS)
178 chromeos::input_method::InputMethodManager::Get()-> 179 chromeos::input_method::InputMethodManager::Get()->
179 AddCandidateWindowObserver(this); 180 AddCandidateWindowObserver(this);
180 #endif 181 #endif
182
183 fade_in_animation_.reset(new gfx::SlideAnimation(this));
184 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR);
185 fade_in_animation_->SetSlideDuration(300);
186 }
187
188 void OmniboxViewViews::FadeIn() {
189 fade_in_animation_->Show();
181 } 190 }
182 191
183 //////////////////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////////////////////
193 // OmniboxViewViews, gfx::AnimationDelegate implementation:
194
195 void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) {
196 if (animation == fade_in_animation_.get()) {
197 SchedulePaint();
198 }
199 }
200
201 void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) {
202 if (animation == fade_in_animation_.get()) {
203 fade_in_animation_->Reset();
204 }
205 }
206
207 ////////////////////////////////////////////////////////////////////////////////
184 // OmniboxViewViews, views::Textfield implementation: 208 // OmniboxViewViews, views::Textfield implementation:
185 209
186 const char* OmniboxViewViews::GetClassName() const { 210 const char* OmniboxViewViews::GetClassName() const {
187 return kViewClassName; 211 return kViewClassName;
188 } 212 }
189 213
214 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) {
215 if (fade_in_animation_->is_animating()) {
216 canvas->SaveLayerAlpha(static_cast<uint8>(
217 fade_in_animation_->CurrentValueBetween(0, 255)));
218 views::Textfield::OnPaint(canvas);
219 canvas->Restore();
220 } else {
221 views::Textfield::OnPaint(canvas);
222 }
223 }
224
190 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { 225 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
191 select_all_on_mouse_release_ = 226 select_all_on_mouse_release_ =
192 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 227 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
193 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); 228 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE));
194 if (select_all_on_mouse_release_) { 229 if (select_all_on_mouse_release_) {
195 // Restore caret visibility whenever the user clicks in the omnibox in a way 230 // Restore caret visibility whenever the user clicks in the omnibox in a way
196 // that would give it focus. We must handle this case separately here 231 // that would give it focus. We must handle this case separately here
197 // because if the omnibox currently has invisible focus, the mouse event 232 // because if the omnibox currently has invisible focus, the mouse event
198 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). 233 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus().
199 model()->SetCaretVisibility(true); 234 model()->SetCaretVisibility(true);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 native_view = client->GetFocusedWindow(); 434 native_view = client->GetFocusedWindow();
400 } 435 }
401 #endif 436 #endif
402 model()->OnWillKillFocus(native_view); 437 model()->OnWillKillFocus(native_view);
403 // Close the popup. 438 // Close the popup.
404 CloseOmniboxPopup(); 439 CloseOmniboxPopup();
405 440
406 // Tell the model to reset itself. 441 // Tell the model to reset itself.
407 model()->OnKillFocus(); 442 model()->OnKillFocus();
408 443
409 OnDidKillFocus();
410
411 // Make sure the beginning of the text is visible. 444 // Make sure the beginning of the text is visible.
412 SelectRange(gfx::Range(0)); 445 SelectRange(gfx::Range(0));
446
447 OnDidKillFocus();
413 } 448 }
414 449
415 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { 450 base::string16 OmniboxViewViews::GetSelectionClipboardText() const {
416 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); 451 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText());
417 } 452 }
418 453
419 //////////////////////////////////////////////////////////////////////////////// 454 ////////////////////////////////////////////////////////////////////////////////
420 // OmniboxViewViews, OmniboxView implementation: 455 // OmniboxViewViews, OmniboxView implementation:
421 456
422 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) { 457 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); 773 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
739 } 774 }
740 775
741 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { 776 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
742 switch (command_id) { 777 switch (command_id) {
743 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). 778 // These commands don't invoke the popup via OnBefore/AfterPossibleChange().
744 case IDS_PASTE_AND_GO: 779 case IDS_PASTE_AND_GO:
745 model()->PasteAndGo(GetClipboardText()); 780 model()->PasteAndGo(GetClipboardText());
746 break; 781 break;
747 case IDS_SHOW_URL: 782 case IDS_SHOW_URL:
748 ShowURL(); 783 controller()->ShowURL();
749 break; 784 break;
750 case IDC_EDIT_SEARCH_ENGINES: 785 case IDC_EDIT_SEARCH_ENGINES:
751 command_updater()->ExecuteCommand(command_id); 786 command_updater()->ExecuteCommand(command_id);
752 break; 787 break;
753 788
754 default: 789 default:
755 OnBeforePossibleChange(); 790 OnBeforePossibleChange();
756 if (command_id == IDS_APP_PASTE) 791 if (command_id == IDS_APP_PASTE)
757 OnPaste(); 792 OnPaste();
758 else if (Textfield::IsCommandIdEnabled(command_id)) 793 else if (Textfield::IsCommandIdEnabled(command_id))
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 const base::string16 text(GetClipboardText()); 1032 const base::string16 text(GetClipboardText());
998 if (!text.empty()) { 1033 if (!text.empty()) {
999 // Record this paste, so we can do different behavior. 1034 // Record this paste, so we can do different behavior.
1000 model()->OnPaste(); 1035 model()->OnPaste();
1001 // Force a Paste operation to trigger the text_changed code in 1036 // Force a Paste operation to trigger the text_changed code in
1002 // OnAfterPossibleChange(), even if identical contents are pasted. 1037 // OnAfterPossibleChange(), even if identical contents are pasted.
1003 text_before_change_.clear(); 1038 text_before_change_.clear();
1004 InsertOrReplaceText(text); 1039 InsertOrReplaceText(text);
1005 } 1040 }
1006 } 1041 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698