OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | |
6 | |
7 #include "chrome/browser/instant/instant_controller.h" | |
8 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | |
9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | |
10 #include "ui/base/animation/multi_animation.h" | |
11 #include "ui/gfx/canvas.h" | |
12 #include "ui/gfx/color_utils.h" | |
13 | |
14 SuggestedTextView::SuggestedTextView(OmniboxEditModel* edit_model, | |
15 bool instant_extended_api_enabled) | |
16 : edit_model_(edit_model), | |
17 instant_extended_api_enabled_(instant_extended_api_enabled), | |
18 bg_color_(0) { | |
19 SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
20 SetAutoColorReadabilityEnabled(false); | |
21 SetEnabledColor(LocationBarView::GetColor(instant_extended_api_enabled_, | |
22 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | |
23 } | |
24 | |
25 SuggestedTextView::~SuggestedTextView() { | |
26 } | |
27 | |
28 void SuggestedTextView::StartAnimation() { | |
29 StopAnimation(); | |
30 | |
31 animation_.reset(CreateAnimation()); | |
32 animation_->Start(); | |
33 UpdateBackgroundColor(); | |
34 } | |
35 | |
36 void SuggestedTextView::StopAnimation() { | |
37 if (animation_.get()) { | |
38 // Reset the delegate so that we don't attempt to commit in AnimationEnded. | |
39 animation_->set_delegate(NULL); | |
40 animation_.reset(NULL); | |
41 SetEnabledColor(LocationBarView::GetColor(instant_extended_api_enabled_, | |
42 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | |
43 SchedulePaint(); | |
44 } | |
45 } | |
46 | |
47 void SuggestedTextView::OnPaintBackground(gfx::Canvas* canvas) { | |
48 if (!animation_.get() || animation_->GetCurrentValue() == 0) | |
49 return; | |
50 | |
51 // TODO(sky): these numbers need to come from the edit. | |
52 canvas->FillRect(gfx::Rect(0, 2, width(), height() - 5), bg_color_); | |
53 } | |
54 | |
55 void SuggestedTextView::AnimationEnded(const ui::Animation* animation) { | |
56 edit_model_->CommitSuggestedText(false); | |
57 } | |
58 | |
59 void SuggestedTextView::AnimationProgressed(const ui::Animation* animation) { | |
60 UpdateBackgroundColor(); | |
61 | |
62 SkColor fg_color = LocationBarView::GetColor(instant_extended_api_enabled_, | |
63 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT); | |
64 SkColor sel_fg_color = LocationBarView::GetColor( | |
65 instant_extended_api_enabled_, ToolbarModel::NONE, | |
66 LocationBarView::SELECTED_TEXT); | |
67 SetEnabledColor(color_utils::AlphaBlend(sel_fg_color, fg_color, | |
68 ui::Tween::ValueBetween(animation->GetCurrentValue(), 0, 255))); | |
69 | |
70 SchedulePaint(); | |
71 } | |
72 | |
73 void SuggestedTextView::AnimationCanceled(const ui::Animation* animation) { | |
74 } | |
75 | |
76 ui::Animation* SuggestedTextView::CreateAnimation() { | |
77 ui::MultiAnimation::Parts parts; | |
78 parts.push_back(ui::MultiAnimation::Part( | |
79 InstantController::kInlineAutocompletePauseTimeMS, ui::Tween::ZERO)); | |
80 parts.push_back(ui::MultiAnimation::Part( | |
81 InstantController::kInlineAutocompleteFadeInTimeMS, ui::Tween::EASE_IN)); | |
82 ui::MultiAnimation* animation = new ui::MultiAnimation(parts); | |
83 animation->set_delegate(this); | |
84 animation->set_continuous(false); | |
85 return animation; | |
86 } | |
87 | |
88 void SuggestedTextView::UpdateBackgroundColor() { | |
89 if (!animation_.get()) { | |
90 // Background only painted while animating. | |
91 return; | |
92 } | |
93 | |
94 double value = animation_->GetCurrentValue(); | |
95 SkColor bg_color = LocationBarView::GetColor(instant_extended_api_enabled_, | |
96 ToolbarModel::NONE, LocationBarView::BACKGROUND); | |
97 #if defined(OS_WIN) | |
98 SkColor s_color = color_utils::GetSysSkColor(COLOR_HIGHLIGHT); | |
99 #else | |
100 // TODO(sky): fix me. | |
101 NOTIMPLEMENTED(); | |
102 SkColor s_color = SK_ColorLTGRAY; | |
103 #endif | |
104 bg_color_ = color_utils::AlphaBlend(s_color, bg_color, | |
105 ui::Tween::ValueBetween(value, 0, 255)); | |
106 } | |
OLD | NEW |