| 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/location_bar/web_intents_button_view.h" | 5 #include "chrome/browser/ui/views/location_bar/web_intents_button_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 7 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents.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 "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "ui/base/animation/slide_animation.h" | 11 #include "ui/base/animation/slide_animation.h" |
| 12 #include "ui/base/animation/tween.h" | 12 #include "ui/base/animation/tween.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | |
| 15 | 14 |
| 16 // Animation time to open the button. | 15 // Animation time to open the button. |
| 17 const int kMoveTimeMs = 150; | 16 const int kMoveTimeMs = 150; |
| 18 | 17 |
| 19 WebIntentsButtonView::WebIntentsButtonView(LocationBarView* parent, | 18 WebIntentsButtonView::WebIntentsButtonView(LocationBarView* parent, |
| 20 const int background_images[]) | 19 const int background_images[], |
| 21 : LocationBarDecorationView(parent, background_images) { | 20 const gfx::Font& font, |
| 21 SkColor font_color) |
| 22 : LocationBarDecorationView(parent, background_images, font, font_color) { |
| 22 } | 23 } |
| 23 | 24 |
| 24 void WebIntentsButtonView::Update(TabContents* tab_contents) { | 25 void WebIntentsButtonView::Update(TabContents* tab_contents) { |
| 25 if (!tab_contents || | 26 if (!tab_contents || |
| 26 !tab_contents->web_intent_picker_controller() || | 27 !tab_contents->web_intent_picker_controller() || |
| 27 !tab_contents->web_intent_picker_controller()-> | 28 !tab_contents->web_intent_picker_controller()-> |
| 28 ShowLocationBarPickerTool()) { | 29 ShowLocationBarPickerTool()) { |
| 29 SetVisible(false); | 30 SetVisible(false); |
| 30 } else { | 31 return; |
| 31 SetVisible(true); | |
| 32 } | 32 } |
| 33 | 33 |
| 34 int animated_string_id = IDS_INTENT_PICKER_USE_ANOTHER_SERVICE; | 34 int animated_string_id = IDS_INTENT_PICKER_USE_ANOTHER_SERVICE; |
| 35 string16 animated_text = l10n_util::GetStringUTF16(animated_string_id); | 35 string16 animated_text = l10n_util::GetStringUTF16(animated_string_id); |
| 36 SetTooltipText(animated_text); | 36 SetTooltipText(animated_text); |
| 37 SetVisible(true); |
| 37 | 38 |
| 39 // Set the flag to draw text before we start to draw the label, to avoid |
| 40 // any possible race. |
| 41 AlwaysDrawText(); |
| 38 StartLabelAnimation(animated_text, kMoveTimeMs); | 42 StartLabelAnimation(animated_text, kMoveTimeMs); |
| 39 AlwaysDrawText(); | |
| 40 } | 43 } |
| 41 | 44 |
| 42 void WebIntentsButtonView::OnClick(LocationBarView* parent) { | 45 void WebIntentsButtonView::OnClick(LocationBarView* parent) { |
| 43 TabContents* tab_contents = parent->GetTabContents(); | 46 TabContents* tab_contents = parent->GetTabContents(); |
| 44 if (!tab_contents) | 47 if (!tab_contents) |
| 45 return; | 48 return; |
| 46 | 49 |
| 47 tab_contents->web_intent_picker_controller()->LocationBarPickerToolClicked(); | 50 tab_contents->web_intent_picker_controller()->LocationBarPickerToolClicked(); |
| 48 } | 51 } |
| 49 | 52 |
| 50 int WebIntentsButtonView::GetTextAnimationSize(double state, int text_size) { | 53 int WebIntentsButtonView::GetTextAnimationSize(double state, int text_size) { |
| 51 if (state < 1.0) { | 54 if (state < 1.0) { |
| 52 return static_cast<int>(text_size * state); | 55 return static_cast<int>(text_size * state); |
| 53 } | 56 } |
| 54 | 57 |
| 55 return text_size; | 58 return text_size; |
| 56 } | 59 } |
| OLD | NEW |