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

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 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 ////////////////////////////////////////////////////////////////////////////////
184 // OmniboxViewViews, views::Textfield implementation: 193 // OmniboxViewViews, views::Textfield implementation:
185 194
186 const char* OmniboxViewViews::GetClassName() const { 195 const char* OmniboxViewViews::GetClassName() const {
187 return kViewClassName; 196 return kViewClassName;
188 } 197 }
189 198
199 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) {
200 if (fade_in_animation_->is_animating()) {
201 canvas->SaveLayerAlpha(static_cast<uint8>(
202 fade_in_animation_->CurrentValueBetween(0, 255)));
203 views::Textfield::OnPaint(canvas);
204 canvas->Restore();
205 } else {
206 views::Textfield::OnPaint(canvas);
207 }
208 }
209
190 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { 210 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
191 select_all_on_mouse_release_ = 211 select_all_on_mouse_release_ =
192 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 212 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
193 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); 213 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE));
194 if (select_all_on_mouse_release_) { 214 if (select_all_on_mouse_release_) {
195 // Restore caret visibility whenever the user clicks in the omnibox in a way 215 // 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 216 // that would give it focus. We must handle this case separately here
197 // because if the omnibox currently has invisible focus, the mouse event 217 // because if the omnibox currently has invisible focus, the mouse event
198 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). 218 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus().
199 model()->SetCaretVisibility(true); 219 model()->SetCaretVisibility(true);
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); 758 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
739 } 759 }
740 760
741 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { 761 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
742 switch (command_id) { 762 switch (command_id) {
743 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). 763 // These commands don't invoke the popup via OnBefore/AfterPossibleChange().
744 case IDS_PASTE_AND_GO: 764 case IDS_PASTE_AND_GO:
745 model()->PasteAndGo(GetClipboardText()); 765 model()->PasteAndGo(GetClipboardText());
746 break; 766 break;
747 case IDS_SHOW_URL: 767 case IDS_SHOW_URL:
748 ShowURL(); 768 controller()->ShowURL();
749 break; 769 break;
750 case IDC_EDIT_SEARCH_ENGINES: 770 case IDC_EDIT_SEARCH_ENGINES:
751 command_updater()->ExecuteCommand(command_id); 771 command_updater()->ExecuteCommand(command_id);
752 break; 772 break;
753 773
754 default: 774 default:
755 OnBeforePossibleChange(); 775 OnBeforePossibleChange();
756 if (command_id == IDS_APP_PASTE) 776 if (command_id == IDS_APP_PASTE)
757 OnPaste(); 777 OnPaste();
758 else if (Textfield::IsCommandIdEnabled(command_id)) 778 else if (Textfield::IsCommandIdEnabled(command_id))
759 Textfield::ExecuteCommand(command_id, event_flags); 779 Textfield::ExecuteCommand(command_id, event_flags);
760 else 780 else
761 command_updater()->ExecuteCommand(command_id); 781 command_updater()->ExecuteCommand(command_id);
762 OnAfterPossibleChange(); 782 OnAfterPossibleChange();
763 break; 783 break;
764 } 784 }
765 } 785 }
766 786
767 //////////////////////////////////////////////////////////////////////////////// 787 ////////////////////////////////////////////////////////////////////////////////
788 // OmniboxViewViews, gfx::AnimationDelegate implementation:
789
790 void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) {
791 SchedulePaint();
792 }
793
794 void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) {
795 fade_in_animation_->Reset();
796 }
797
798 ////////////////////////////////////////////////////////////////////////////////
768 // OmniboxViewViews, views::TextfieldController implementation: 799 // OmniboxViewViews, views::TextfieldController implementation:
769 800
770 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, 801 void OmniboxViewViews::ContentsChanged(views::Textfield* sender,
771 const base::string16& new_contents) { 802 const base::string16& new_contents) {
772 } 803 }
773 804
774 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, 805 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
775 const ui::KeyEvent& event) { 806 const ui::KeyEvent& event) {
776 delete_at_end_pressed_ = false; 807 delete_at_end_pressed_ = false;
777 808
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 const base::string16 text(GetClipboardText()); 1028 const base::string16 text(GetClipboardText());
998 if (!text.empty()) { 1029 if (!text.empty()) {
999 // Record this paste, so we can do different behavior. 1030 // Record this paste, so we can do different behavior.
1000 model()->OnPaste(); 1031 model()->OnPaste();
1001 // Force a Paste operation to trigger the text_changed code in 1032 // Force a Paste operation to trigger the text_changed code in
1002 // OnAfterPossibleChange(), even if identical contents are pasted. 1033 // OnAfterPossibleChange(), even if identical contents are pasted.
1003 text_before_change_.clear(); 1034 text_before_change_.clear();
1004 InsertOrReplaceText(text); 1035 InsertOrReplaceText(text);
1005 } 1036 }
1006 } 1037 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698