Index: chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
index 8474bcf4510524bda98276c35380e89be7feb2fa..3539b80ec0f38fb115012a341828fda4cecc6347 100644 |
--- a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
+++ b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
@@ -7,28 +7,22 @@ |
#include "chrome/browser/search/search.h" |
#include "chrome/browser/ui/omnibox/omnibox_popup_non_view.h" |
#include "chrome/browser/ui/omnibox/omnibox_view.h" |
-#include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
#include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
+#include "chrome/browser/ui/views/omnibox/omnibox_view_delegate.h" |
#include "chrome/browser/ui/views/omnibox/touch_omnibox_popup_contents_view.h" |
+#include "grit/theme_resources.h" |
+#include "grit/ui_resources.h" |
#include "ui/base/theme_provider.h" |
#include "ui/gfx/canvas.h" |
#include "ui/gfx/image/image.h" |
#include "ui/gfx/path.h" |
+#include "ui/views/controls/image_view.h" |
#include "ui/views/widget/widget.h" |
#if defined(USE_AURA) |
#include "ui/views/corewm/window_animations.h" |
#endif |
-#if defined(OS_WIN) |
-#include <dwmapi.h> |
- |
-#include "base/win/scoped_gdi_object.h" |
-#if !defined(USE_AURA) |
-#include "ui/base/win/shell.h" |
-#endif |
-#endif |
- |
namespace { |
const SkAlpha kGlassPopupAlpha = 240; |
@@ -43,6 +37,10 @@ const int kEditFontAdjust = 0; |
const int kEditFontAdjust = -1; |
#endif |
+// This is the number of pixels in the border image interior to the actual |
+// border. |
+const int kBorderInterior = 6; |
+ |
} // namespace |
class OmniboxPopupContentsView::AutocompletePopupWidget |
@@ -63,17 +61,17 @@ OmniboxPopupView* OmniboxPopupContentsView::Create( |
const gfx::Font& font, |
OmniboxView* omnibox_view, |
OmniboxEditModel* edit_model, |
- views::View* location_bar) { |
+ OmniboxViewDelegate* view_delegate) { |
if (chrome::IsInstantExtendedAPIEnabled()) |
return new OmniboxPopupNonView(edit_model); |
OmniboxPopupContentsView* view = NULL; |
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { |
view = new TouchOmniboxPopupContentsView( |
- font, omnibox_view, edit_model, location_bar); |
+ font, omnibox_view, edit_model, view_delegate); |
} else { |
view = new OmniboxPopupContentsView( |
- font, omnibox_view, edit_model, location_bar); |
+ font, omnibox_view, edit_model, view_delegate); |
} |
view->Init(); |
@@ -84,18 +82,26 @@ OmniboxPopupContentsView::OmniboxPopupContentsView( |
const gfx::Font& font, |
OmniboxView* omnibox_view, |
OmniboxEditModel* edit_model, |
- views::View* location_bar) |
+ OmniboxViewDelegate* view_delegate) |
: model_(new OmniboxPopupModel(this, edit_model)), |
omnibox_view_(omnibox_view), |
- location_bar_(location_bar), |
+ view_delegate_(view_delegate), |
font_(font.DeriveFont(kEditFontAdjust)), |
ignore_mouse_drag_(false), |
- size_animation_(this) { |
- bubble_border_ = new views::BubbleBorder(views::BubbleBorder::NONE, |
- views::BubbleBorder::NO_SHADOW, SK_ColorWHITE); |
- set_border(const_cast<views::BubbleBorder*>(bubble_border_)); |
+ size_animation_(this), |
+ provider_logo_(new views::ImageView), |
+ left_margin_(0), |
+ right_margin_(0), |
+ outside_vertical_padding_(0) { |
// The contents is owned by the LocationBarView. |
set_owned_by_client(); |
+ |
+ ui::ThemeProvider* theme = view_delegate_->GetThemeProviderForPopup(); |
+ provider_logo_->set_owned_by_client(); |
Peter Kasting
2013/06/06 18:52:16
Why use set_owned_by_client() and a scoped_ptr ins
|
+ provider_logo_->SetImage(theme->GetImageSkiaNamed(IDR_OMNIBOX_GOOGLE_LOGO)); |
+ provider_logo_->SizeToPreferredSize(); |
+ |
+ bottom_shadow_ = theme->GetImageSkiaNamed(IDR_BUBBLE_B); |
} |
void OmniboxPopupContentsView::Init() { |
@@ -107,6 +113,7 @@ void OmniboxPopupContentsView::Init() { |
result_view->SetVisible(false); |
AddChildViewAt(result_view, static_cast<int>(i)); |
} |
+ AddChildView(provider_logo_.get()); |
} |
OmniboxPopupContentsView::~OmniboxPopupContentsView() { |
@@ -133,12 +140,16 @@ gfx::Rect OmniboxPopupContentsView::GetPopupBounds() const { |
void OmniboxPopupContentsView::LayoutChildren() { |
gfx::Rect contents_rect = GetContentsBounds(); |
- int top = contents_rect.y(); |
- for (int i = 0; i < child_count(); ++i) { |
+ |
+ provider_logo_->SetPosition(gfx::Point(5, 5)); |
Peter Kasting
2013/06/06 18:52:16
These numbers are pretty magic
|
+ |
+ int top = contents_rect.y() + outside_vertical_padding_; |
+ int left = contents_rect.x() + left_margin_; |
+ int width = contents_rect.width() - left_margin_ - right_margin_; |
Peter Kasting
2013/06/06 18:52:16
Or just:
contents_rect.Inset(left_margin_, outs
|
+ for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
View* v = child_at(i); |
if (v->visible()) { |
- v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
- v->GetPreferredSize().height()); |
+ v->SetBounds(left, top, width, v->GetPreferredSize().height()); |
top = v->bounds().bottom(); |
} |
} |
@@ -186,7 +197,7 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() { |
view->SetMatch(GetMatchAtIndex(i)); |
view->SetVisible(true); |
} |
- for (size_t i = result_size; i < child_rv_count; ++i) |
+ for (size_t i = result_size; i < AutocompleteResult::kMaxMatches; ++i) |
child_at(i)->SetVisible(false); |
gfx::Rect new_target_bounds = CalculateTargetBounds(CalculatePopupHeight()); |
@@ -205,9 +216,9 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() { |
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
params.can_activate = false; |
params.transparent = true; |
- params.parent = location_bar_->GetWidget()->GetNativeView(); |
+ params.parent = view_delegate_->GetPopupParent(); |
params.bounds = GetPopupBounds(); |
- params.context = location_bar_->GetWidget()->GetNativeView(); |
+ params.context = view_delegate_->GetPopupParent(); |
popup_->Init(params); |
#if defined(USE_AURA) |
views::corewm::SetWindowVisibilityAnimationType( |
@@ -287,8 +298,6 @@ void OmniboxPopupContentsView::AnimationProgressed( |
// OmniboxPopupContentsView, views::View overrides: |
void OmniboxPopupContentsView::Layout() { |
- UpdateBlurRegion(); |
- |
// Size our children to the available content area. |
LayoutChildren(); |
@@ -385,39 +394,54 @@ int OmniboxPopupContentsView::CalculatePopupHeight() { |
int popup_height = 0; |
for (size_t i = 0; i < model_->result().size(); ++i) |
popup_height += child_at(i)->GetPreferredSize().height(); |
- return popup_height; |
+ |
+ // Add enough space on the top and bottom so it looks like there is the same |
+ // amount of space between the text and the popup border as there is in the |
+ // interior between each row of text. |
+ // |
+ // Discovering the exact amount of leading and padding around the font is |
+ // a bit tricky and platform-specific, but this computation seems to work in |
+ // practice. |
+ OmniboxResultView* result_view = result_view_at(0); |
+ outside_vertical_padding_ = |
+ (result_view->GetPreferredSize().height() - |
+ result_view->GetTextHeight()); |
+ |
+ return popup_height + outside_vertical_padding_ * 2 + |
+ bottom_shadow_->height() - kBorderInterior; |
} |
OmniboxResultView* OmniboxPopupContentsView::CreateResultView( |
OmniboxResultViewModel* model, |
int model_index, |
const gfx::Font& font) { |
- return new OmniboxResultView(model, model_index, location_bar_, font); |
+ return new OmniboxResultView(model, model_index, view_delegate_, font); |
} |
//////////////////////////////////////////////////////////////////////////////// |
// OmniboxPopupContentsView, views::View overrides, protected: |
void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { |
+ gfx::Rect contents_bounds = GetContentsBounds(); |
+ contents_bounds.set_height( |
+ contents_bounds.height() - bottom_shadow_->height() + kBorderInterior); |
+ |
gfx::Path path; |
- MakeContentsPath(&path, GetContentsBounds()); |
+ MakeContentsPath(&path, contents_bounds); |
canvas->Save(); |
canvas->sk_canvas()->clipPath(path, |
SkRegion::kIntersect_Op, |
true /* doAntialias */); |
PaintResultViews(canvas); |
- |
- // We want the contents background to be slightly transparent so we can see |
- // the blurry glass effect on DWM systems behind. We do this _after_ we paint |
- // the children since they paint text, and GDI will reset this alpha data if |
- // we paint text after this call. |
- MakeCanvasTransparent(canvas); |
canvas->Restore(); |
// Now we paint the border, so it will be alpha-blended atop the contents. |
// This looks slightly better in the corners than drawing the contents atop |
// the border. |
- OnPaintBorder(canvas); |
+ //OnPaintBorder(canvas); |
Peter Kasting
2013/06/06 18:52:16
Remove this
|
+ |
+ canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(), |
+ width(), bottom_shadow_->height()); |
} |
void OmniboxPopupContentsView::PaintChildren(gfx::Canvas* canvas) { |
@@ -444,42 +468,7 @@ void OmniboxPopupContentsView::MakeContentsPath( |
SkIntToScalar(bounding_rect.y()), |
SkIntToScalar(bounding_rect.right()), |
SkIntToScalar(bounding_rect.bottom())); |
- |
- SkScalar radius = SkIntToScalar(views::BubbleBorder::GetCornerRadius()); |
- path->addRoundRect(rect, radius, radius); |
-} |
- |
-void OmniboxPopupContentsView::UpdateBlurRegion() { |
-#if defined(OS_WIN) && !defined(USE_AURA) |
- // We only support background blurring on Vista with Aero-Glass enabled. |
- if (!ui::win::IsAeroGlassEnabled() || !GetWidget()) |
- return; |
- |
- // Provide a blurred background effect within the contents region of the |
- // popup. |
- DWM_BLURBEHIND bb = {0}; |
- bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; |
- bb.fEnable = true; |
- |
- // Translate the contents rect into widget coordinates, since that's what |
- // DwmEnableBlurBehindWindow expects a region in. |
- gfx::Rect contents_rect = ConvertRectToWidget(GetContentsBounds()); |
- gfx::Path contents_path; |
- MakeContentsPath(&contents_path, contents_rect); |
- base::win::ScopedGDIObject<HRGN> popup_region; |
- popup_region.Set(contents_path.CreateNativeRegion()); |
- bb.hRgnBlur = popup_region.Get(); |
- DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); |
-#endif |
-} |
- |
-void OmniboxPopupContentsView::MakeCanvasTransparent(gfx::Canvas* canvas) { |
- // Allow the window blur effect to show through the popup background. |
- SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? |
- kGlassPopupAlpha : kOpaquePopupAlpha; |
- canvas->DrawColor(SkColorSetA( |
- result_view_at(0)->GetColor(OmniboxResultView::NORMAL, |
- OmniboxResultView::BACKGROUND), alpha), SkXfermode::kDstIn_Mode); |
+ path->addRect(rect); |
} |
void OmniboxPopupContentsView::OpenIndex(size_t index, |
@@ -512,25 +501,12 @@ size_t OmniboxPopupContentsView::GetIndexForPoint( |
} |
gfx::Rect OmniboxPopupContentsView::CalculateTargetBounds(int h) { |
Peter Kasting
2013/06/06 18:52:16
This can be inlined into its caller too
|
- gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); |
- const views::Border* border = location_bar_->border(); |
- if (border) { |
- // Adjust for the border so that the bubble and location bar borders are |
- // aligned. |
- gfx::Insets insets = border->GetInsets(); |
- location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0); |
- } else { |
- // The normal location bar is drawn using a background graphic that includes |
- // the border, so we inset by enough to make the edges line up, and the |
- // bubble appear at the same height as the Star bubble. |
- location_bar_bounds.Inset(LocationBarView::kNormalHorizontalEdgeThickness, |
- 0); |
- } |
- gfx::Point location_bar_origin(location_bar_bounds.origin()); |
- views::View::ConvertPointToScreen(location_bar_, &location_bar_origin); |
- location_bar_bounds.set_origin(location_bar_origin); |
- return bubble_border_->GetBounds( |
- location_bar_bounds, gfx::Size(location_bar_bounds.width(), h)); |
+ gfx::Point top_left_screen_coord; |
+ int width; |
+ view_delegate_->GetPopupPositioningInfo( |
+ &top_left_screen_coord, &width, &left_margin_, &right_margin_); |
+ |
+ return gfx::Rect(top_left_screen_coord, gfx::Size(width, h)); |
} |
void OmniboxPopupContentsView::UpdateLineEvent( |