| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/location_bar/suggested_text_view.h" | 5 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 7 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 8 #include "chrome/browser/instant/instant_controller.h" | 8 #include "chrome/browser/instant/instant_controller.h" |
| 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 10 #include "ui/base/animation/multi_animation.h" | 10 #include "ui/base/animation/multi_animation.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
| 13 | 13 |
| 14 SuggestedTextView::SuggestedTextView(AutocompleteEditModel* edit_model) | 14 SuggestedTextView::SuggestedTextView(AutocompleteEditModel* edit_model) |
| 15 : edit_model_(edit_model), | 15 : edit_model_(edit_model), |
| 16 bg_color_(0) { | 16 bg_color_(0) { |
| 17 SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 18 SetAutoColorReadabilityEnabled(false); |
| 19 SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, |
| 20 LocationBarView::DEEMPHASIZED_TEXT)); |
| 17 } | 21 } |
| 18 | 22 |
| 19 SuggestedTextView::~SuggestedTextView() { | 23 SuggestedTextView::~SuggestedTextView() { |
| 20 } | 24 } |
| 21 | 25 |
| 22 void SuggestedTextView::StartAnimation() { | 26 void SuggestedTextView::StartAnimation() { |
| 23 StopAnimation(); | 27 StopAnimation(); |
| 24 | 28 |
| 25 animation_.reset(CreateAnimation()); | 29 animation_.reset(CreateAnimation()); |
| 26 animation_->Start(); | 30 animation_->Start(); |
| 27 UpdateBackgroundColor(); | 31 UpdateBackgroundColor(); |
| 28 } | 32 } |
| 29 | 33 |
| 30 void SuggestedTextView::StopAnimation() { | 34 void SuggestedTextView::StopAnimation() { |
| 31 if (animation_.get()) { | 35 if (animation_.get()) { |
| 32 // Reset the delegate so that we don't attempt to commit in AnimationEnded. | 36 // Reset the delegate so that we don't attempt to commit in AnimationEnded. |
| 33 animation_->set_delegate(NULL); | 37 animation_->set_delegate(NULL); |
| 34 animation_.reset(NULL); | 38 animation_.reset(NULL); |
| 35 SetColor(LocationBarView::GetColor(ToolbarModel::NONE, | 39 SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, |
| 36 LocationBarView::DEEMPHASIZED_TEXT)); | 40 LocationBarView::DEEMPHASIZED_TEXT)); |
| 37 SchedulePaint(); | 41 SchedulePaint(); |
| 38 } | 42 } |
| 39 } | 43 } |
| 40 | 44 |
| 41 void SuggestedTextView::OnPaintBackground(gfx::Canvas* canvas) { | 45 void SuggestedTextView::OnPaintBackground(gfx::Canvas* canvas) { |
| 42 if (!animation_.get() || animation_->GetCurrentValue() == 0) | 46 if (!animation_.get() || animation_->GetCurrentValue() == 0) |
| 43 return; | 47 return; |
| 44 | 48 |
| 45 // TODO(sky): these numbers need to come from the edit. | 49 // TODO(sky): these numbers need to come from the edit. |
| 46 canvas->FillRectInt(bg_color_, 0, 2, width(), height() - 5); | 50 canvas->FillRectInt(bg_color_, 0, 2, width(), height() - 5); |
| 47 } | 51 } |
| 48 | 52 |
| 49 void SuggestedTextView::AnimationEnded(const ui::Animation* animation) { | 53 void SuggestedTextView::AnimationEnded(const ui::Animation* animation) { |
| 50 edit_model_->CommitSuggestedText(false); | 54 edit_model_->CommitSuggestedText(false); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void SuggestedTextView::AnimationProgressed(const ui::Animation* animation) { | 57 void SuggestedTextView::AnimationProgressed(const ui::Animation* animation) { |
| 54 UpdateBackgroundColor(); | 58 UpdateBackgroundColor(); |
| 55 | 59 |
| 56 SkColor fg_color = LocationBarView::GetColor( | 60 SkColor fg_color = LocationBarView::GetColor( |
| 57 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT); | 61 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT); |
| 58 SkColor sel_fg_color = LocationBarView::GetColor( | 62 SkColor sel_fg_color = LocationBarView::GetColor( |
| 59 ToolbarModel::NONE, LocationBarView::SELECTED_TEXT); | 63 ToolbarModel::NONE, LocationBarView::SELECTED_TEXT); |
| 60 SetColor(color_utils::AlphaBlend( | 64 SetEnabledColor(color_utils::AlphaBlend(sel_fg_color, fg_color, |
| 61 sel_fg_color, fg_color, | |
| 62 ui::Tween::ValueBetween(animation->GetCurrentValue(), 0, 255))); | 65 ui::Tween::ValueBetween(animation->GetCurrentValue(), 0, 255))); |
| 63 | 66 |
| 64 SchedulePaint(); | 67 SchedulePaint(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 void SuggestedTextView::AnimationCanceled(const ui::Animation* animation) { | 70 void SuggestedTextView::AnimationCanceled(const ui::Animation* animation) { |
| 68 } | 71 } |
| 69 | 72 |
| 70 ui::Animation* SuggestedTextView::CreateAnimation() { | 73 ui::Animation* SuggestedTextView::CreateAnimation() { |
| 71 ui::MultiAnimation::Parts parts; | 74 ui::MultiAnimation::Parts parts; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 91 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
| 92 SkColor s_color = color_utils::GetSysSkColor(COLOR_HIGHLIGHT); | 95 SkColor s_color = color_utils::GetSysSkColor(COLOR_HIGHLIGHT); |
| 93 #else | 96 #else |
| 94 // TODO(sky): fix me. | 97 // TODO(sky): fix me. |
| 95 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
| 96 SkColor s_color = SK_ColorLTGRAY; | 99 SkColor s_color = SK_ColorLTGRAY; |
| 97 #endif | 100 #endif |
| 98 bg_color_ = color_utils::AlphaBlend(s_color, bg_color, | 101 bg_color_ = color_utils::AlphaBlend(s_color, bg_color, |
| 99 ui::Tween::ValueBetween(value, 0, 255)); | 102 ui::Tween::ValueBetween(value, 0, 255)); |
| 100 } | 103 } |
| OLD | NEW |