| 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 | 14 |
| 15 // Animation time to open the button. | 15 // Animation time to open the button. |
| 16 const int kMoveTimeMs = 150; | 16 const int kMoveTimeMs = 150; |
| 17 | 17 |
| 18 WebIntentsButtonView::WebIntentsButtonView(LocationBarView* parent, | 18 WebIntentsButtonView::WebIntentsButtonView(LocationBarView* parent, |
| 19 const int background_images[], | 19 const int background_images[], |
| 20 const gfx::Font& font, | 20 const gfx::Font& font, |
| 21 SkColor font_color) | 21 SkColor font_color) |
| 22 : LocationBarDecorationView(parent, background_images, font, font_color) { | 22 : LocationBarDecorationView(parent, background_images, font, font_color) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 void WebIntentsButtonView::Update(TabContents* tab_contents) { | 25 void WebIntentsButtonView::Update(TabContents* tab_contents) { |
| 26 if (!tab_contents || | 26 WebIntentPickerController* web_intent_picker_controller = |
| 27 !tab_contents->web_intent_picker_controller() || | 27 tab_contents ? WebIntentPickerController::FromWebContents( |
| 28 !tab_contents->web_intent_picker_controller()-> | 28 tab_contents->web_contents()) |
| 29 ShowLocationBarPickerTool()) { | 29 : NULL; |
| 30 if (!web_intent_picker_controller || |
| 31 !web_intent_picker_controller->ShowLocationBarPickerTool()) { |
| 30 SetVisible(false); | 32 SetVisible(false); |
| 31 return; | 33 return; |
| 32 } | 34 } |
| 33 | 35 |
| 34 int animated_string_id = IDS_INTENT_PICKER_USE_ANOTHER_SERVICE; | 36 int animated_string_id = IDS_INTENT_PICKER_USE_ANOTHER_SERVICE; |
| 35 string16 animated_text = l10n_util::GetStringUTF16(animated_string_id); | 37 string16 animated_text = l10n_util::GetStringUTF16(animated_string_id); |
| 36 SetTooltipText(animated_text); | 38 SetTooltipText(animated_text); |
| 37 SetVisible(true); | 39 SetVisible(true); |
| 38 | 40 |
| 39 // Set the flag to draw text before we start to draw the label, to avoid | 41 // Set the flag to draw text before we start to draw the label, to avoid |
| 40 // any possible race. | 42 // any possible race. |
| 41 AlwaysDrawText(); | 43 AlwaysDrawText(); |
| 42 StartLabelAnimation(animated_text, kMoveTimeMs); | 44 StartLabelAnimation(animated_text, kMoveTimeMs); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void WebIntentsButtonView::OnClick(LocationBarView* parent) { | 47 void WebIntentsButtonView::OnClick(LocationBarView* parent) { |
| 46 TabContents* tab_contents = parent->GetTabContents(); | 48 TabContents* tab_contents = parent->GetTabContents(); |
| 47 if (!tab_contents) | 49 if (!tab_contents) |
| 48 return; | 50 return; |
| 49 | 51 |
| 50 tab_contents->web_intent_picker_controller()->LocationBarPickerToolClicked(); | 52 WebIntentPickerController::FromWebContents(tab_contents->web_contents())-> |
| 53 LocationBarPickerToolClicked(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 int WebIntentsButtonView::GetTextAnimationSize(double state, int text_size) { | 56 int WebIntentsButtonView::GetTextAnimationSize(double state, int text_size) { |
| 54 if (state < 1.0) { | 57 if (state < 1.0) { |
| 55 return static_cast<int>(text_size * state); | 58 return static_cast<int>(text_size * state); |
| 56 } | 59 } |
| 57 | 60 |
| 58 return text_size; | 61 return text_size; |
| 59 } | 62 } |
| OLD | NEW |