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