| 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/omnibox/location_bar_util.h" | 5 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/extensions/extension_action.h" |
| 10 #include "third_party/skia/include/core/SkPaint.h" |
| 11 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 9 #include "ui/base/text/text_elider.h" | 12 #include "ui/base/text/text_elider.h" |
| 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/color_utils.h" |
| 15 #include "ui/gfx/rect.h" |
| 10 | 16 |
| 11 namespace location_bar_util { | 17 namespace location_bar_util { |
| 12 | 18 |
| 13 string16 CalculateMinString(const string16& description) { | 19 string16 CalculateMinString(const string16& description) { |
| 14 // Chop at the first '.' or whitespace. | 20 // Chop at the first '.' or whitespace. |
| 15 const size_t dot_index = description.find('.'); | 21 const size_t dot_index = description.find('.'); |
| 16 const size_t ws_index = description.find_first_of(kWhitespaceUTF16); | 22 const size_t ws_index = description.find_first_of(kWhitespaceUTF16); |
| 17 size_t chop_index = std::min(dot_index, ws_index); | 23 size_t chop_index = std::min(dot_index, ws_index); |
| 18 string16 min_string; | 24 string16 min_string; |
| 19 if (chop_index == string16::npos) { | 25 if (chop_index == string16::npos) { |
| 20 // No dot or whitespace, truncate to at most 3 chars. | 26 // No dot or whitespace, truncate to at most 3 chars. |
| 21 min_string = ui::TruncateString(description, 3); | 27 min_string = ui::TruncateString(description, 3); |
| 22 } else { | 28 } else { |
| 23 min_string = description.substr(0, chop_index); | 29 min_string = description.substr(0, chop_index); |
| 24 } | 30 } |
| 25 base::i18n::AdjustStringForLocaleDirection(&min_string); | 31 base::i18n::AdjustStringForLocaleDirection(&min_string); |
| 26 return min_string; | 32 return min_string; |
| 27 } | 33 } |
| 28 | 34 |
| 35 |
| 36 void PaintExtensionActionBackground(const ExtensionAction& action, |
| 37 int tab_id, |
| 38 gfx::Canvas* canvas, |
| 39 const gfx::Rect& bounds, |
| 40 SkColor text_color, |
| 41 SkColor background_color) { |
| 42 if (!action.WantsAttention(tab_id)) |
| 43 return; |
| 44 |
| 45 SkPoint gradient_bounds[2] = { {SkIntToScalar(bounds.x()), |
| 46 SkIntToScalar(bounds.y())}, |
| 47 {SkIntToScalar(bounds.x()), |
| 48 SkIntToScalar(bounds.bottom())} }; |
| 49 SkColor gradient_colors[2] = { |
| 50 color_utils::AlphaBlend(text_color, background_color, 0x13), |
| 51 color_utils::AlphaBlend(text_color, background_color, 0x1d) |
| 52 }; |
| 53 SkShader* gradient = SkGradientShader::CreateLinear( |
| 54 gradient_bounds, gradient_colors, NULL, 2, SkShader::kClamp_TileMode); |
| 55 SkPaint paint; |
| 56 paint.setShader(gradient); |
| 57 gradient->unref(); |
| 58 canvas->DrawRect(bounds, paint); |
| 59 |
| 60 SkColor border_color = |
| 61 color_utils::AlphaBlend(text_color, background_color, 0x55); |
| 62 canvas->DrawLine(bounds.origin(), |
| 63 gfx::Point(bounds.x(), bounds.bottom()), |
| 64 border_color); |
| 65 // "-1" because gfx::Rects are half-open, not including their right or |
| 66 // bottom edges. |
| 67 canvas->DrawLine(gfx::Point(bounds.right() - 1, bounds.y()), |
| 68 gfx::Point(bounds.right() - 1, bounds.bottom()), |
| 69 border_color); |
| 70 } |
| 71 |
| 29 } // namespace location_bar_util | 72 } // namespace location_bar_util |
| OLD | NEW |