| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/autocomplete/autocomplete_popup_contents_view.h" | 5 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" | 
| 6 | 6 | 
| 7 #include "app/bidi_line_iterator.h" | 7 #include "app/bidi_line_iterator.h" | 
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" | 
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" | 
| 10 #include "app/theme_provider.h" | 10 #include "app/theme_provider.h" | 
| 11 #include "app/text_elider.h" | 11 #include "app/text_elider.h" | 
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" | 
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" | 
| 14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 
| 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 
| 16 #include "chrome/browser/views/bubble_border.h" | 16 #include "chrome/browser/views/bubble_border.h" | 
|  | 17 #include "chrome/browser/views/location_bar/location_bar_view.h" | 
| 17 #include "gfx/canvas.h" | 18 #include "gfx/canvas.h" | 
| 18 #include "gfx/color_utils.h" | 19 #include "gfx/color_utils.h" | 
| 19 #include "gfx/insets.h" | 20 #include "gfx/insets.h" | 
| 20 #include "gfx/path.h" | 21 #include "gfx/path.h" | 
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" | 
| 22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" | 
| 23 #include "third_party/skia/include/core/SkShader.h" | 24 #include "third_party/skia/include/core/SkShader.h" | 
| 24 #include "third_party/icu/public/common/unicode/ubidi.h" | 25 #include "third_party/icu/public/common/unicode/ubidi.h" | 
| 25 #include "views/widget/widget.h" | 26 #include "views/widget/widget.h" | 
| 26 | 27 | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 86 const SkAlpha kGlassPopupAlpha = 240; | 87 const SkAlpha kGlassPopupAlpha = 240; | 
| 87 const SkAlpha kOpaquePopupAlpha = 255; | 88 const SkAlpha kOpaquePopupAlpha = 255; | 
| 88 // The minimum distance between the top and bottom of the icon and the top or | 89 // The minimum distance between the top and bottom of the icon and the top or | 
| 89 // bottom of the row. "Minimum" is used because the vertical padding may be | 90 // bottom of the row. "Minimum" is used because the vertical padding may be | 
| 90 // larger, depending on the size of the text. | 91 // larger, depending on the size of the text. | 
| 91 const int kIconVerticalPadding = 2; | 92 const int kIconVerticalPadding = 2; | 
| 92 // The minimum distance between the top and bottom of the text and the top or | 93 // The minimum distance between the top and bottom of the text and the top or | 
| 93 // bottom of the row. See comment about the use of "minimum" for | 94 // bottom of the row. See comment about the use of "minimum" for | 
| 94 // kIconVerticalPadding. | 95 // kIconVerticalPadding. | 
| 95 const int kTextVerticalPadding = 3; | 96 const int kTextVerticalPadding = 3; | 
| 96 // The padding between horizontally adjacent items (including row edges). |  | 
| 97 const int kHorizontalPadding = 3; |  | 
| 98 // The size delta between the font used for the edit and the result rows. Passed | 97 // The size delta between the font used for the edit and the result rows. Passed | 
| 99 // to gfx::Font::DeriveFont. | 98 // to gfx::Font::DeriveFont. | 
| 100 #if !defined(OS_CHROMEOS) | 99 #if !defined(OS_CHROMEOS) | 
| 101 const int kEditFontAdjust = -1; | 100 const int kEditFontAdjust = -1; | 
| 102 #else | 101 #else | 
| 103 // Don't adjust font on chromeos as it becomes too small. | 102 // Don't adjust font on chromeos as it becomes too small. | 
| 104 const int kEditFontAdjust = 0; | 103 const int kEditFontAdjust = 0; | 
| 105 #endif | 104 #endif | 
| 106 | 105 | 
| 107 } | 106 } | 
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 299         ACMatchClassification(0, ACMatchClassification::NONE)); | 298         ACMatchClassification(0, ACMatchClassification::NONE)); | 
| 300     x = DrawString(canvas, separator, classifications, true, x, | 299     x = DrawString(canvas, separator, classifications, true, x, | 
| 301                    text_bounds_.y()); | 300                    text_bounds_.y()); | 
| 302 | 301 | 
| 303     DrawString(canvas, match_.description, match_.description_class, true, x, | 302     DrawString(canvas, match_.description, match_.description_class, true, x, | 
| 304                text_bounds_.y()); | 303                text_bounds_.y()); | 
| 305   } | 304   } | 
| 306 } | 305 } | 
| 307 | 306 | 
| 308 void AutocompleteResultView::Layout() { | 307 void AutocompleteResultView::Layout() { | 
| 309   icon_bounds_.SetRect(kHorizontalPadding, (height() - icon_size_) / 2, | 308   icon_bounds_.SetRect(LocationBarView::kItemPadding, | 
| 310                        icon_size_, icon_size_); | 309                        (height() - icon_size_) / 2, icon_size_, icon_size_); | 
| 311   int text_x = icon_bounds_.right() + kHorizontalPadding; | 310   int text_x = icon_bounds_.right() + LocationBarView::kItemPadding; | 
| 312   int font_height = std::max(normal_font_.height(), bold_font_.height()); | 311   int font_height = std::max(normal_font_.height(), bold_font_.height()); | 
| 313   text_bounds_.SetRect(text_x, std::max(0, (height() - font_height) / 2), | 312   text_bounds_.SetRect(text_x, std::max(0, (height() - font_height) / 2), | 
| 314       std::max(0, bounds().width() - text_x - kHorizontalPadding), font_height); | 313       std::max(0, bounds().width() - text_x - LocationBarView::kItemPadding), | 
|  | 314       font_height); | 
| 315 } | 315 } | 
| 316 | 316 | 
| 317 gfx::Size AutocompleteResultView::GetPreferredSize() { | 317 gfx::Size AutocompleteResultView::GetPreferredSize() { | 
| 318   int text_height = std::max(normal_font_.height(), bold_font_.height()) + | 318   int text_height = std::max(normal_font_.height(), bold_font_.height()) + | 
| 319       (kTextVerticalPadding * 2); | 319       (kTextVerticalPadding * 2); | 
| 320   int icon_height = icon_size_ + (kIconVerticalPadding * 2); | 320   int icon_height = icon_size_ + (kIconVerticalPadding * 2); | 
| 321   return gfx::Size(0, std::max(icon_height, text_height)); | 321   return gfx::Size(0, std::max(icon_height, text_height)); | 
| 322 } | 322 } | 
| 323 | 323 | 
| 324 // static | 324 // static | 
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 663       result_view = new AutocompleteResultView(this, i, result_font_); | 663       result_view = new AutocompleteResultView(this, i, result_font_); | 
| 664       AddChildView(result_view); | 664       AddChildView(result_view); | 
| 665     } else { | 665     } else { | 
| 666       result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); | 666       result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); | 
| 667     } | 667     } | 
| 668     result_view->set_match(GetMatchAtIndex(i)); | 668     result_view->set_match(GetMatchAtIndex(i)); | 
| 669     total_child_height += result_view->GetPreferredSize().height(); | 669     total_child_height += result_view->GetPreferredSize().height(); | 
| 670   } | 670   } | 
| 671 | 671 | 
| 672   // Calculate desired bounds. | 672   // Calculate desired bounds. | 
| 673   gfx::Rect location_bar_bounds(location_bar_->bounds()); | 673   gfx::Rect location_bar_bounds(gfx::Point(), location_bar_->size()); | 
| 674   gfx::Point location; |  | 
| 675   const views::Border* border = location_bar_->border(); | 674   const views::Border* border = location_bar_->border(); | 
| 676   int location_bar_height = location_bar_bounds.height(); |  | 
| 677   if (border) { | 675   if (border) { | 
| 678     // Adjust for the border so that the bubble and location bar borders are | 676     // Adjust for the border so that the bubble and location bar borders are | 
| 679     // aligned. | 677     // aligned. | 
| 680     gfx::Insets insets; | 678     gfx::Insets insets; | 
| 681     border->GetInsets(&insets); | 679     border->GetInsets(&insets); | 
| 682     location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0); | 680     location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0); | 
| 683     location.Offset(insets.left(), 0); |  | 
| 684   } else { | 681   } else { | 
| 685     // The normal location bar is drawn using a background graphic that includes | 682     // The normal location bar is drawn using a background graphic that includes | 
| 686     // the border.  The graphic is actually one pixel larger above and below the | 683     // the border, so we inset by enough to make the edges line up, and the | 
| 687     // dark of the border, so that it can draw a faint highlight. | 684     // bubble appear at the same height as the Star bubble. | 
| 688     // So, in order to make the popup butt up against the dark border, it has to | 685     location_bar_bounds.Inset(LocationBarView::kEdgeThickness, 0); | 
| 689     // overlap the location bar by one pixel. |  | 
| 690     location_bar_height -= 1; |  | 
| 691   } | 686   } | 
| 692   views::View::ConvertPointToScreen(location_bar_, &location); | 687   gfx::Point location_bar_origin(location_bar_bounds.origin()); | 
| 693   location_bar_bounds.set_origin(location); | 688   views::View::ConvertPointToScreen(location_bar_, &location_bar_origin); | 
| 694   location_bar_bounds.set_height(location_bar_height); | 689   location_bar_bounds.set_origin(location_bar_origin); | 
| 695   gfx::Rect new_target_bounds(bubble_border_->GetBounds(location_bar_bounds, | 690   gfx::Rect new_target_bounds(bubble_border_->GetBounds(location_bar_bounds, | 
| 696       gfx::Size(location_bar_bounds.width(), total_child_height))); | 691       gfx::Size(location_bar_bounds.width(), total_child_height))); | 
| 697 | 692 | 
| 698   // If we're animating and our target height changes, reset the animation. | 693   // If we're animating and our target height changes, reset the animation. | 
| 699   // NOTE: If we just reset blindly on _every_ update, then when the user types | 694   // NOTE: If we just reset blindly on _every_ update, then when the user types | 
| 700   // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 695   // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 
| 701   // last few pixels to get to one visible result. | 696   // last few pixels to get to one visible result. | 
| 702   if (new_target_bounds.height() != target_bounds_.height()) | 697   if (new_target_bounds.height() != target_bounds_.height()) | 
| 703     size_animation_.Reset(); | 698     size_animation_.Reset(); | 
| 704   target_bounds_ = new_target_bounds; | 699   target_bounds_ = new_target_bounds; | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 893 void AutocompletePopupContentsView::MakeContentsPath( | 888 void AutocompletePopupContentsView::MakeContentsPath( | 
| 894     gfx::Path* path, | 889     gfx::Path* path, | 
| 895     const gfx::Rect& bounding_rect) { | 890     const gfx::Rect& bounding_rect) { | 
| 896   SkRect rect; | 891   SkRect rect; | 
| 897   rect.set(SkIntToScalar(bounding_rect.x()), | 892   rect.set(SkIntToScalar(bounding_rect.x()), | 
| 898            SkIntToScalar(bounding_rect.y()), | 893            SkIntToScalar(bounding_rect.y()), | 
| 899            SkIntToScalar(bounding_rect.right()), | 894            SkIntToScalar(bounding_rect.right()), | 
| 900            SkIntToScalar(bounding_rect.bottom())); | 895            SkIntToScalar(bounding_rect.bottom())); | 
| 901 | 896 | 
| 902   SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 897   SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 
| 903   SkScalar scaled_radius = | 898   path->addRoundRect(rect, radius, radius); | 
| 904       SkScalarMul(radius, (SK_ScalarSqrt2 - SK_Scalar1) * 4 / 3); |  | 
| 905   path->moveTo(rect.fRight, rect.fTop); |  | 
| 906   path->lineTo(rect.fRight, rect.fBottom - radius); |  | 
| 907   path->cubicTo(rect.fRight, rect.fBottom - radius + scaled_radius, |  | 
| 908                rect.fRight - radius + scaled_radius, rect.fBottom, |  | 
| 909                rect.fRight - radius, rect.fBottom); |  | 
| 910   path->lineTo(rect.fLeft + radius, rect.fBottom); |  | 
| 911   path->cubicTo(rect.fLeft + radius - scaled_radius, rect.fBottom, |  | 
| 912                rect.fLeft, rect.fBottom - radius + scaled_radius, |  | 
| 913                rect.fLeft, rect.fBottom - radius); |  | 
| 914   path->lineTo(rect.fLeft, rect.fTop); |  | 
| 915   path->close(); |  | 
| 916 } | 899 } | 
| 917 | 900 | 
| 918 void AutocompletePopupContentsView::UpdateBlurRegion() { | 901 void AutocompletePopupContentsView::UpdateBlurRegion() { | 
| 919 #if defined(OS_WIN) | 902 #if defined(OS_WIN) | 
| 920   // We only support background blurring on Vista with Aero-Glass enabled. | 903   // We only support background blurring on Vista with Aero-Glass enabled. | 
| 921   if (!win_util::ShouldUseVistaFrame() || !GetWidget()) | 904   if (!win_util::ShouldUseVistaFrame() || !GetWidget()) | 
| 922     return; | 905     return; | 
| 923 | 906 | 
| 924   // Provide a blurred background effect within the contents region of the | 907   // Provide a blurred background effect within the contents region of the | 
| 925   // popup. | 908   // popup. | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 978   DCHECK(nb_match <= GetChildViewCount()); | 961   DCHECK(nb_match <= GetChildViewCount()); | 
| 979   for (int i = 0; i < nb_match; ++i) { | 962   for (int i = 0; i < nb_match; ++i) { | 
| 980     views::View* child = GetChildViewAt(i); | 963     views::View* child = GetChildViewAt(i); | 
| 981     gfx::Point point_in_child_coords(point); | 964     gfx::Point point_in_child_coords(point); | 
| 982     View::ConvertPointToView(this, child, &point_in_child_coords); | 965     View::ConvertPointToView(this, child, &point_in_child_coords); | 
| 983     if (child->HitTest(point_in_child_coords)) | 966     if (child->HitTest(point_in_child_coords)) | 
| 984       return i; | 967       return i; | 
| 985   } | 968   } | 
| 986   return AutocompletePopupModel::kNoMatch; | 969   return AutocompletePopupModel::kNoMatch; | 
| 987 } | 970 } | 
| OLD | NEW | 
|---|