| 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/views/omnibox/omnibox_popup_contents_view.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/search/search.h" | 12 #include "chrome/browser/search/search.h" |
| 13 #include "chrome/browser/themes/theme_properties.h" | 13 #include "chrome/browser/themes/theme_properties.h" |
| 14 #include "chrome/browser/ui/layout_constants.h" | 14 #include "chrome/browser/ui/layout_constants.h" |
| 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 16 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 16 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
| 17 #include "chrome/browser/ui/views/theme_copying_widget.h" | 17 #include "chrome/browser/ui/views/theme_copying_widget.h" |
| 18 #include "components/omnibox/browser/omnibox_view.h" | 18 #include "components/omnibox/browser/omnibox_view.h" |
| 19 #include "third_party/skia/include/core/SkDrawLooper.h" | 19 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 20 #include "ui/base/theme_provider.h" | 20 #include "ui/base/theme_provider.h" |
| 21 #include "ui/compositor/clip_recorder.h" | 21 #include "ui/compositor/clip_recorder.h" |
| 22 #include "ui/compositor/paint_recorder.h" | 22 #include "ui/compositor/paint_recorder.h" |
| 23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/geometry/safe_integer_conversions.h" | 24 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 25 #include "ui/gfx/image/canvas_image_source.h" |
| 25 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 26 #include "ui/gfx/image/image_skia_operations.h" | 27 #include "ui/gfx/image/image_skia_operations.h" |
| 27 #include "ui/gfx/path.h" | 28 #include "ui/gfx/path.h" |
| 28 #include "ui/gfx/shadow_value.h" | 29 #include "ui/gfx/shadow_value.h" |
| 29 #include "ui/views/controls/image_view.h" | 30 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/view_targeter.h" | 31 #include "ui/views/view_targeter.h" |
| 31 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
| 32 #include "ui/views/window/non_client_view.h" | 33 #include "ui/views/window/non_client_view.h" |
| 33 | 34 |
| 35 #include "base/json/json_string_value_serializer.h" |
| 36 #include "cc/debug/micro_benchmark_controller.h" |
| 37 #include "cc/raster/one_copy_raster_buffer_provider.h" |
| 38 #include "cc/trees/layer_tree_host.h" |
| 39 #include "ui/aura/window.h" |
| 40 #include "ui/aura/window_delegate.h" |
| 41 #include "ui/events/base_event_utils.h" |
| 42 |
| 34 namespace { | 43 namespace { |
| 35 | 44 |
| 36 // Cache the shadow images so that potentially expensive shadow drawing isn't | 45 namespace test { |
| 46 |
| 47 class Experiment : public ui::CompositorAnimationObserver { |
| 48 public: |
| 49 explicit Experiment(views::View* tabstrip) : tabstrip_(tabstrip) { |
| 50 CHECK(tabstrip_->GetWidget()); |
| 51 compositor_ = tabstrip_->GetWidget()->GetCompositor(); |
| 52 compositor_->AddAnimationObserver(this); |
| 53 // views::View::ConvertPointToWidget(tabstrip_, &start_); |
| 54 // start_.set_y(start_.y() + tabstrip_->height() / 2); |
| 55 |
| 56 CHECK_GT(compositor_->layer_tree_host()->ScheduleMicroBenchmark( |
| 57 "rasterize_and_record_benchmark", |
| 58 base::MakeUnique<base::DictionaryValue>(), |
| 59 base::Bind(&Experiment::BenchmarkDone, base::Unretained(this))), 0); |
| 60 // cc::RasterStats::SetInstance(&stats_); |
| 61 } |
| 62 |
| 63 private: |
| 64 ~Experiment() override { |
| 65 if (compositor_) |
| 66 compositor_->RemoveAnimationObserver(this); |
| 67 } |
| 68 |
| 69 void BenchmarkDone(std::unique_ptr<base::Value> value) { |
| 70 std::string str; |
| 71 JSONStringValueSerializer ser(&str); |
| 72 ser.Serialize(*value); |
| 73 LOG(ERROR) << str; |
| 74 } |
| 75 |
| 76 // ui::CompositorAnimationObserver: |
| 77 void OnAnimationStep(base::TimeTicks timestamp) override { |
| 78 #if 0 |
| 79 gfx::Point location = start_; |
| 80 location.set_x(location.x() + x_); |
| 81 |
| 82 if (inc_) { |
| 83 ++x_; |
| 84 if (x_ >= tabstrip_->max_x()) { |
| 85 --x_; |
| 86 inc_ = false; |
| 87 ++round_trips_; |
| 88 } |
| 89 } else { |
| 90 --x_; |
| 91 if (x_ < 0) { |
| 92 ++x_; |
| 93 inc_ = true; |
| 94 ++round_trips_; |
| 95 } |
| 96 } |
| 97 |
| 98 CHECK_GT(compositor_->layer_tree_host()->ScheduleMicroBenchmark( |
| 99 "rasterize_and_record_benchmark", |
| 100 base::MakeUnique<base::DictionaryValue>(), |
| 101 base::Bind(&Experiment::BenchmarkDone, base::Unretained(this))), 0); |
| 102 ui::MouseEvent move(ui::ET_MOUSE_MOVED, location, location, |
| 103 ui::EventTimeForNow(), |
| 104 ui::EF_NONE, ui::EF_NONE); |
| 105 tabstrip_->GetWidget()->GetNativeWindow()->delegate()->OnMouseEvent(&move); |
| 106 if (round_trips_ >= 2) { |
| 107 LOG(ERROR) << "DONE ===================================================="; |
| 108 LOG(ERROR) << "Total: " << stats_.bytes(); |
| 109 compositor_->RemoveAnimationObserver(this); |
| 110 compositor_ = nullptr; |
| 111 cc::RasterStats::SetInstance(nullptr); |
| 112 } |
| 113 #endif |
| 114 } |
| 115 |
| 116 void OnCompositingShuttingDown(ui::Compositor* compositor) override { |
| 117 CHECK_EQ(compositor_, compositor); |
| 118 compositor_ = nullptr; |
| 119 } |
| 120 |
| 121 views::View* tabstrip_; |
| 122 ui::Compositor* compositor_ = nullptr; |
| 123 // gfx::Point start_; |
| 124 // int x_ = 0; |
| 125 // bool inc_ = true; |
| 126 // int round_trips_ = 0; |
| 127 // cc::RasterStats stats_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(Experiment); |
| 130 }; |
| 131 |
| 132 } // test |
| 133 |
| 134 // This source takes two images and draws one above the other. |
| 135 class StackedImagesImageSource : public gfx::CanvasImageSource { |
| 136 public: |
| 137 StackedImagesImageSource(const gfx::ImageSkia& top, |
| 138 const gfx::ImageSkia& bottom) |
| 139 : CanvasImageSource( |
| 140 gfx::Size(top.width(), top.height() + bottom.height()), |
| 141 false), |
| 142 top_(top), |
| 143 bottom_(bottom) { |
| 144 DCHECK_EQ(top.width(), bottom.width()); |
| 145 } |
| 146 ~StackedImagesImageSource() override {} |
| 147 |
| 148 // CanvasImageSource overrides: |
| 149 void Draw(gfx::Canvas* canvas) override { |
| 150 canvas->DrawImageInt(top_, 0, 0); |
| 151 canvas->DrawImageInt(bottom_, 0, top_.height()); |
| 152 } |
| 153 |
| 154 private: |
| 155 const gfx::ImageSkia top_; |
| 156 const gfx::ImageSkia bottom_; |
| 157 |
| 158 DISALLOW_COPY_AND_ASSIGN(StackedImagesImageSource); |
| 159 }; |
| 160 |
| 161 // Cache the shadow image so that potentially expensive shadow drawing isn't |
| 37 // repeated. | 162 // repeated. |
| 38 base::LazyInstance<gfx::ImageSkia> g_top_shadow = LAZY_INSTANCE_INITIALIZER; | 163 static int g_top_shadow_height = 0; |
| 39 base::LazyInstance<gfx::ImageSkia> g_bottom_shadow = LAZY_INSTANCE_INITIALIZER; | 164 static int g_bottom_shadow_height = 0; |
| 165 base::LazyInstance<gfx::ImageSkia> g_shadow_ninebox = LAZY_INSTANCE_INITIALIZER; |
| 40 | 166 |
| 41 const int kPopupVerticalPadding = 4; | 167 const int kPopupVerticalPadding = 4; |
| 42 | 168 |
| 43 } // namespace | 169 } // namespace |
| 44 | 170 |
| 45 class OmniboxPopupContentsView::AutocompletePopupWidget | 171 class OmniboxPopupContentsView::AutocompletePopupWidget |
| 46 : public ThemeCopyingWidget, | 172 : public ThemeCopyingWidget, |
| 47 public base::SupportsWeakPtr<AutocompletePopupWidget> { | 173 public base::SupportsWeakPtr<AutocompletePopupWidget> { |
| 48 public: | 174 public: |
| 49 explicit AutocompletePopupWidget(views::Widget* role_model) | 175 explicit AutocompletePopupWidget(views::Widget* role_model) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 omnibox_view_(omnibox_view), | 204 omnibox_view_(omnibox_view), |
| 79 location_bar_view_(location_bar_view), | 205 location_bar_view_(location_bar_view), |
| 80 font_list_(font_list), | 206 font_list_(font_list), |
| 81 ignore_mouse_drag_(false), | 207 ignore_mouse_drag_(false), |
| 82 size_animation_(this), | 208 size_animation_(this), |
| 83 start_margin_(0), | 209 start_margin_(0), |
| 84 end_margin_(0) { | 210 end_margin_(0) { |
| 85 // The contents is owned by the LocationBarView. | 211 // The contents is owned by the LocationBarView. |
| 86 set_owned_by_client(); | 212 set_owned_by_client(); |
| 87 | 213 |
| 88 if (g_top_shadow.Get().isNull()) { | 214 if (g_shadow_ninebox.Get().isNull()) { |
| 89 std::vector<gfx::ShadowValue> shadows; | 215 std::vector<gfx::ShadowValue> top_shadows; |
| 90 // Blur by 1dp. See comment below about blur accounting. | 216 // Blur by 1dp. See comment below about blur accounting. |
| 91 shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK); | 217 top_shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK); |
| 92 g_top_shadow.Get() = | 218 gfx::ImageSkia top_shadow_image = |
| 93 gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, false); | 219 gfx::ImageSkiaOperations::CreateHorizontalShadow(top_shadows, false); |
| 94 } | 220 g_top_shadow_height = top_shadow_image.height(); |
| 95 if (g_bottom_shadow.Get().isNull()) { | 221 |
| 222 // Values for the bottom shadow. |
| 96 const int kSmallShadowBlur = 3; | 223 const int kSmallShadowBlur = 3; |
| 97 const int kLargeShadowBlur = 8; | 224 const int kLargeShadowBlur = 8; |
| 98 const int kLargeShadowYOffset = 3; | 225 const int kLargeShadowYOffset = 3; |
| 99 | 226 |
| 100 std::vector<gfx::ShadowValue> shadows; | 227 std::vector<gfx::ShadowValue> bottom_shadows; |
| 101 // gfx::ShadowValue counts blur pixels both inside and outside the shape, | 228 // gfx::ShadowValue counts blur pixels both inside and outside the shape, |
| 102 // whereas these blur values only describe the outside portion, hence they | 229 // whereas these blur values only describe the outside portion, hence they |
| 103 // must be doubled. | 230 // must be doubled. |
| 104 shadows.emplace_back(gfx::Vector2d(), 2 * kSmallShadowBlur, | 231 bottom_shadows.emplace_back(gfx::Vector2d(), 2 * kSmallShadowBlur, |
| 105 SK_ColorBLACK); | 232 SK_ColorBLACK); |
| 106 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowYOffset), | 233 bottom_shadows.emplace_back(gfx::Vector2d(0, kLargeShadowYOffset), |
| 107 2 * kLargeShadowBlur, SK_ColorBLACK); | 234 2 * kLargeShadowBlur, SK_ColorBLACK); |
| 108 | 235 |
| 109 g_bottom_shadow.Get() = | 236 gfx::ImageSkia bottom_shadow_image = |
| 110 gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, true); | 237 gfx::ImageSkiaOperations::CreateHorizontalShadow(bottom_shadows, true); |
| 238 g_bottom_shadow_height = bottom_shadow_image.height(); |
| 239 auto source = |
| 240 new StackedImagesImageSource(top_shadow_image, bottom_shadow_image); |
| 241 g_shadow_ninebox.Get() = gfx::ImageSkia(source, source->size()); |
| 111 } | 242 } |
| 243 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH)); |
| 244 shadow_layer_->SetFillsBoundsOpaquely(false); |
| 245 shadow_layer_->UpdateNinePatchLayerImage(g_shadow_ninebox.Get()); |
| 246 shadow_layer_->UpdateNinePatchLayerAperture( |
| 247 gfx::Rect(0, g_top_shadow_height, 1, 0)); |
| 248 shadow_layer_->UpdateNinePatchLayerBorder(gfx::Rect( |
| 249 0, g_top_shadow_height, 0, g_top_shadow_height + g_bottom_shadow_height)); |
| 112 | 250 |
| 113 SetEventTargeter( | 251 SetEventTargeter( |
| 114 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 252 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 115 } | 253 } |
| 116 | 254 |
| 255 void OmniboxPopupContentsView::ViewHierarchyChanged( |
| 256 const ViewHierarchyChangedDetails& details) { |
| 257 if (experiment_started_) |
| 258 return; |
| 259 if (!GetWidget()) |
| 260 return; |
| 261 new test::Experiment(this); |
| 262 experiment_started_ = true; |
| 263 } |
| 264 |
| 117 void OmniboxPopupContentsView::Init() { | 265 void OmniboxPopupContentsView::Init() { |
| 118 // This can't be done in the constructor as at that point we aren't | 266 // This can't be done in the constructor as at that point we aren't |
| 119 // necessarily our final class yet, and we may have subclasses | 267 // necessarily our final class yet, and we may have subclasses |
| 120 // overriding CreateResultView. | 268 // overriding CreateResultView. |
| 121 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 269 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| 122 OmniboxResultView* result_view = CreateResultView(i, font_list_); | 270 OmniboxResultView* result_view = CreateResultView(i, font_list_); |
| 123 result_view->SetVisible(false); | 271 result_view->SetVisible(false); |
| 124 AddChildViewAt(result_view, static_cast<int>(i)); | 272 AddChildViewAt(result_view, static_cast<int>(i)); |
| 125 } | 273 } |
| 126 } | 274 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 143 int current_height_delta = static_cast<int>( | 291 int current_height_delta = static_cast<int>( |
| 144 size_animation_.GetCurrentValue() * total_height_delta - 0.5); | 292 size_animation_.GetCurrentValue() * total_height_delta - 0.5); |
| 145 current_frame_bounds.set_height( | 293 current_frame_bounds.set_height( |
| 146 current_frame_bounds.height() + current_height_delta); | 294 current_frame_bounds.height() + current_height_delta); |
| 147 return current_frame_bounds; | 295 return current_frame_bounds; |
| 148 } | 296 } |
| 149 | 297 |
| 150 void OmniboxPopupContentsView::LayoutChildren() { | 298 void OmniboxPopupContentsView::LayoutChildren() { |
| 151 gfx::Rect contents_rect = GetContentsBounds(); | 299 gfx::Rect contents_rect = GetContentsBounds(); |
| 152 contents_rect.Inset(gfx::Insets(kPopupVerticalPadding, 0)); | 300 contents_rect.Inset(gfx::Insets(kPopupVerticalPadding, 0)); |
| 153 contents_rect.Inset(start_margin_, g_top_shadow.Get().height(), end_margin_, | 301 contents_rect.Inset(start_margin_, 0, end_margin_, |
| 154 0); | 302 0); |
| 155 | 303 |
| 156 int top = contents_rect.y(); | 304 int top = contents_rect.y(); |
| 157 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 305 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| 158 View* v = child_at(i); | 306 View* v = child_at(i); |
| 159 if (v->visible()) { | 307 if (v->visible()) { |
| 160 v->SetBounds(contents_rect.x(), top, contents_rect.width(), | 308 v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
| 161 v->GetPreferredSize().height()); | 309 v->GetPreferredSize().height()); |
| 162 top = v->bounds().bottom(); | 310 top = v->bounds().bottom(); |
| 163 } | 311 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 max_match_contents_width_, view->GetMatchContentsWidth()); | 369 max_match_contents_width_, view->GetMatchContentsWidth()); |
| 222 } | 370 } |
| 223 } | 371 } |
| 224 | 372 |
| 225 for (size_t i = result_size; i < AutocompleteResult::kMaxMatches; ++i) | 373 for (size_t i = result_size; i < AutocompleteResult::kMaxMatches; ++i) |
| 226 child_at(i)->SetVisible(false); | 374 child_at(i)->SetVisible(false); |
| 227 | 375 |
| 228 // We want the popup to appear to overlay the bottom of the toolbar. So we | 376 // We want the popup to appear to overlay the bottom of the toolbar. So we |
| 229 // shift the popup to completely cover the client edge, and then draw an | 377 // shift the popup to completely cover the client edge, and then draw an |
| 230 // additional semitransparent shadow above that. | 378 // additional semitransparent shadow above that. |
| 231 int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness + | 379 int top_edge_overlap = |
| 232 g_top_shadow.Get().height(); | 380 views::NonClientFrameView::kClientEdgeThickness /*+ g_top_shadow_height*/; |
| 233 | 381 |
| 234 gfx::Point top_left_screen_coord; | 382 gfx::Point top_left_screen_coord; |
| 235 int width; | 383 int width; |
| 236 location_bar_view_->GetOmniboxPopupPositioningInfo( | 384 location_bar_view_->GetOmniboxPopupPositioningInfo( |
| 237 &top_left_screen_coord, &width, &start_margin_, | 385 &top_left_screen_coord, &width, &start_margin_, |
| 238 &end_margin_, top_edge_overlap); | 386 &end_margin_, top_edge_overlap); |
| 239 gfx::Rect new_target_bounds(top_left_screen_coord, | 387 gfx::Rect new_target_bounds(top_left_screen_coord, |
| 240 gfx::Size(width, CalculatePopupHeight())); | 388 gfx::Size(width, CalculatePopupHeight())); |
| 241 | 389 |
| 242 // If we're animating and our target height changes, reset the animation. | 390 // If we're animating and our target height changes, reset the animation. |
| 243 // NOTE: If we just reset blindly on _every_ update, then when the user types | 391 // NOTE: If we just reset blindly on _every_ update, then when the user types |
| 244 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 392 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the |
| 245 // last few pixels to get to one visible result. | 393 // last few pixels to get to one visible result. |
| 246 if (new_target_bounds.height() != target_bounds_.height()) | 394 if (new_target_bounds.height() != target_bounds_.height()) |
| 247 size_animation_.Reset(); | 395 size_animation_.Reset(); |
| 248 target_bounds_ = new_target_bounds; | 396 target_bounds_ = new_target_bounds; |
| 249 | 397 |
| 250 if (!popup_) { | 398 if (!popup_) { |
| 399 // Create a new layer even if one already exists to make sure it's correctly |
| 400 // parented. |
| 401 SetPaintToLayer(false); |
| 402 SetPaintToLayer(true); |
| 403 layer()->SetFillsBoundsOpaquely(false); |
| 404 layer()->Add(shadow_layer_.get()); |
| 405 |
| 251 views::Widget* popup_parent = location_bar_view_->GetWidget(); | 406 views::Widget* popup_parent = location_bar_view_->GetWidget(); |
| 252 | 407 |
| 253 // If the popup is currently closed, we need to create it. | 408 // If the popup is currently closed, we need to create it. |
| 254 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr(); | 409 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr(); |
| 255 | 410 |
| 256 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 411 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 257 #if defined(OS_WIN) | 412 #if defined(OS_WIN) |
| 258 // On Windows use the software compositor to ensure that we don't block | 413 // On Windows use the software compositor to ensure that we don't block |
| 259 // the UI thread blocking issue during command buffer creation. We can | 414 // the UI thread blocking issue during command buffer creation. We can |
| 260 // revert this change once http://crbug.com/125248 is fixed. | 415 // revert this change once http://crbug.com/125248 is fixed. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // We need to manually schedule a paint here since we are a layered window and | 507 // We need to manually schedule a paint here since we are a layered window and |
| 353 // won't implicitly require painting until we ask for one. | 508 // won't implicitly require painting until we ask for one. |
| 354 SchedulePaint(); | 509 SchedulePaint(); |
| 355 } | 510 } |
| 356 | 511 |
| 357 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( | 512 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( |
| 358 const gfx::Point& point) { | 513 const gfx::Point& point) { |
| 359 return nullptr; | 514 return nullptr; |
| 360 } | 515 } |
| 361 | 516 |
| 517 void OmniboxPopupContentsView::OnBoundsChanged( |
| 518 const gfx::Rect& previous_bounds) { |
| 519 gfx::Rect shadow_bounds = GetLocalBounds(); |
| 520 shadow_layer_->UpdateNinePatchOcclusion(shadow_bounds); |
| 521 shadow_bounds.Inset( |
| 522 gfx::Insets(-g_top_shadow_height, 0, -g_bottom_shadow_height, 0)); |
| 523 shadow_layer_->SetBounds(shadow_bounds); |
| 524 } |
| 525 |
| 362 bool OmniboxPopupContentsView::OnMousePressed( | 526 bool OmniboxPopupContentsView::OnMousePressed( |
| 363 const ui::MouseEvent& event) { | 527 const ui::MouseEvent& event) { |
| 364 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. | 528 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. |
| 365 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) | 529 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) |
| 366 UpdateLineEvent(event, event.IsLeftMouseButton()); | 530 UpdateLineEvent(event, event.IsLeftMouseButton()); |
| 367 return true; | 531 return true; |
| 368 } | 532 } |
| 369 | 533 |
| 370 bool OmniboxPopupContentsView::OnMouseDragged( | 534 bool OmniboxPopupContentsView::OnMouseDragged( |
| 371 const ui::MouseEvent& event) { | 535 const ui::MouseEvent& event) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 593 |
| 430 int OmniboxPopupContentsView::CalculatePopupHeight() { | 594 int OmniboxPopupContentsView::CalculatePopupHeight() { |
| 431 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 595 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 432 int popup_height = 0; | 596 int popup_height = 0; |
| 433 for (size_t i = 0; i < model_->result().size(); ++i) | 597 for (size_t i = 0; i < model_->result().size(); ++i) |
| 434 popup_height += child_at(i)->GetPreferredSize().height(); | 598 popup_height += child_at(i)->GetPreferredSize().height(); |
| 435 | 599 |
| 436 // Add enough space on the top and bottom so it looks like there is the same | 600 // Add enough space on the top and bottom so it looks like there is the same |
| 437 // amount of space between the text and the popup border as there is in the | 601 // amount of space between the text and the popup border as there is in the |
| 438 // interior between each row of text. | 602 // interior between each row of text. |
| 439 return popup_height + kPopupVerticalPadding * 2 + | 603 return popup_height + kPopupVerticalPadding * 2; |
| 440 g_top_shadow.Get().height() + g_bottom_shadow.Get().height(); | |
| 441 } | 604 } |
| 442 | 605 |
| 443 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( | 606 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( |
| 444 int model_index, | 607 int model_index, |
| 445 const gfx::FontList& font_list) { | 608 const gfx::FontList& font_list) { |
| 446 return new OmniboxResultView(this, model_index, font_list); | 609 return new OmniboxResultView(this, model_index, font_list); |
| 447 } | 610 } |
| 448 | 611 |
| 449 //////////////////////////////////////////////////////////////////////////////// | 612 //////////////////////////////////////////////////////////////////////////////// |
| 450 // OmniboxPopupContentsView, views::View overrides, private: | 613 // OmniboxPopupContentsView, views::View overrides, private: |
| 451 | 614 |
| 452 const char* OmniboxPopupContentsView::GetClassName() const { | 615 const char* OmniboxPopupContentsView::GetClassName() const { |
| 453 return "OmniboxPopupContentsView"; | 616 return "OmniboxPopupContentsView"; |
| 454 } | 617 } |
| 455 | 618 |
| 456 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { | |
| 457 canvas->TileImageInt(g_top_shadow.Get(), 0, 0, width(), | |
| 458 g_top_shadow.Get().height()); | |
| 459 canvas->TileImageInt(g_bottom_shadow.Get(), 0, | |
| 460 height() - g_bottom_shadow.Get().height(), width(), | |
| 461 g_bottom_shadow.Get().height()); | |
| 462 } | |
| 463 | |
| 464 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { | 619 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { |
| 465 gfx::Rect contents_bounds = GetContentsBounds(); | 620 gfx::Rect contents_bounds = GetContentsBounds(); |
| 466 contents_bounds.Inset(0, g_top_shadow.Get().height(), 0, | |
| 467 g_bottom_shadow.Get().height()); | |
| 468 | 621 |
| 469 ui::ClipRecorder clip_recorder(context); | 622 ui::ClipRecorder clip_recorder(context); |
| 470 clip_recorder.ClipRect(contents_bounds); | 623 clip_recorder.ClipRect(contents_bounds); |
| 471 { | 624 { |
| 472 ui::PaintRecorder recorder(context, size()); | 625 ui::PaintRecorder recorder(context, size()); |
| 473 SkColor background_color = result_view_at(0)->GetColor( | 626 SkColor background_color = result_view_at(0)->GetColor( |
| 474 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); | 627 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); |
| 475 recorder.canvas()->DrawColor(background_color); | 628 recorder.canvas()->DrawColor(background_color); |
| 476 } | 629 } |
| 477 View::PaintChildren(context); | 630 View::PaintChildren(context); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 size_t index = GetIndexForPoint(event.location()); | 680 size_t index = GetIndexForPoint(event.location()); |
| 528 if (!HasMatchAt(index)) | 681 if (!HasMatchAt(index)) |
| 529 return; | 682 return; |
| 530 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 683 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
| 531 GURL(), base::string16(), index); | 684 GURL(), base::string16(), index); |
| 532 } | 685 } |
| 533 | 686 |
| 534 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 687 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
| 535 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 688 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
| 536 } | 689 } |
| OLD | NEW |