| 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/intents/web_intent_picker.h" | |
| 6 | |
| 7 #include <cmath> | |
| 8 | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/extensions/extension_install_prompt.h" | |
| 11 #include "chrome/browser/intents/web_intents_util.h" | |
| 12 #include "content/public/browser/web_contents.h" | |
| 13 #include "content/public/browser/web_contents_view.h" | |
| 14 #include "grit/generated_resources.h" | |
| 15 #include "grit/theme_resources.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/gfx/size.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Maximum inline disposition container sizes. | |
| 22 const int kMaxInlineDispositionWidth = 900; | |
| 23 const int kMaxInlineDispositionHeight = 900; | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 void WebIntentPicker::OnShowExtensionInstallDialog( | |
| 28 const ExtensionInstallPrompt::ShowParams& show_params, | |
| 29 ExtensionInstallPrompt::Delegate* delegate, | |
| 30 const ExtensionInstallPrompt::Prompt& prompt) { | |
| 31 ExtensionInstallPrompt::GetDefaultShowDialogCallback().Run( | |
| 32 show_params, delegate, prompt); | |
| 33 } | |
| 34 | |
| 35 gfx::Size WebIntentPicker::GetMinInlineDispositionSize() { | |
| 36 return gfx::Size(1, 1); | |
| 37 } | |
| 38 | |
| 39 gfx::Size WebIntentPicker::GetMaxInlineDispositionSize() { | |
| 40 return gfx::Size(kMaxInlineDispositionWidth, kMaxInlineDispositionHeight); | |
| 41 } | |
| 42 | |
| 43 // static | |
| 44 int WebIntentPicker::GetNthStarImageIdFromCWSRating(double rating, int index) { | |
| 45 // The fractional part of the rating is converted to stars as: | |
| 46 // [0, 0.33) -> round down | |
| 47 // [0.33, 0.66] -> half star | |
| 48 // (0.66, 1) -> round up | |
| 49 const double kHalfStarMin = 0.33; | |
| 50 const double kHalfStarMax = 0.66; | |
| 51 | |
| 52 // Add 1 + kHalfStarMax to make values with fraction > 0.66 round up. | |
| 53 int full_stars = std::floor(rating + 1 - kHalfStarMax); | |
| 54 | |
| 55 if (index < full_stars) | |
| 56 return IDR_CWS_STAR_FULL; | |
| 57 | |
| 58 // We don't need to test against the upper bound (kHalfStarMax); when the | |
| 59 // fractional part is greater than kHalfStarMax, full_stars will be rounded | |
| 60 // up, which means rating - full_stars is negative. | |
| 61 bool half_star = rating - full_stars >= kHalfStarMin; | |
| 62 | |
| 63 return index == full_stars && half_star ? | |
| 64 IDR_CWS_STAR_HALF : | |
| 65 IDR_CWS_STAR_EMPTY; | |
| 66 } | |
| 67 | |
| 68 // static | |
| 69 string16 WebIntentPicker::GetDisplayStringForIntentAction( | |
| 70 const string16& action16) { | |
| 71 std::string action(UTF16ToUTF8(action16)); | |
| 72 if (!action.compare(web_intents::kActionShare)) | |
| 73 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SHARE); | |
| 74 else if (!action.compare(web_intents::kActionEdit)) | |
| 75 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_EDIT); | |
| 76 else if (!action.compare(web_intents::kActionView)) | |
| 77 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_VIEW); | |
| 78 else if (!action.compare(web_intents::kActionPick)) | |
| 79 // Using generic string per UX suggestions. | |
| 80 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_CHOOSE_SERVICE); | |
| 81 else if (!action.compare(web_intents::kActionSubscribe)) | |
| 82 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SUBSCRIBE); | |
| 83 else if (!action.compare(web_intents::kActionSave)) | |
| 84 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SAVE); | |
| 85 else | |
| 86 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_CHOOSE_SERVICE); | |
| 87 } | |
| OLD | NEW |