Chromium Code Reviews| 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 "chrome/browser/search/search.h" | 9 #include "chrome/browser/search/search.h" |
| 10 #include "chrome/browser/themes/theme_properties.h" | 10 #include "chrome/browser/themes/theme_properties.h" |
| 11 #include "chrome/browser/ui/views/layout_constants.h" | |
| 11 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 13 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
| 13 #include "components/omnibox/browser/omnibox_view.h" | 14 #include "components/omnibox/browser/omnibox_view.h" |
| 14 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 15 #include "ui/base/resource/material_design/material_design_controller.h" | 16 #include "ui/base/resource/material_design/material_design_controller.h" |
| 16 #include "ui/base/theme_provider.h" | 17 #include "ui/base/theme_provider.h" |
| 17 #include "ui/compositor/clip_transform_recorder.h" | 18 #include "ui/compositor/clip_transform_recorder.h" |
| 18 #include "ui/compositor/paint_recorder.h" | 19 #include "ui/compositor/paint_recorder.h" |
| 19 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 // white pixels at the bottom of the popup as long when animating very small | 109 // white pixels at the bottom of the popup as long when animating very small |
| 109 // height differences. | 110 // height differences. |
| 110 int current_height_delta = static_cast<int>( | 111 int current_height_delta = static_cast<int>( |
| 111 size_animation_.GetCurrentValue() * total_height_delta - 0.5); | 112 size_animation_.GetCurrentValue() * total_height_delta - 0.5); |
| 112 current_frame_bounds.set_height( | 113 current_frame_bounds.set_height( |
| 113 current_frame_bounds.height() + current_height_delta); | 114 current_frame_bounds.height() + current_height_delta); |
| 114 return current_frame_bounds; | 115 return current_frame_bounds; |
| 115 } | 116 } |
| 116 | 117 |
| 117 void OmniboxPopupContentsView::LayoutChildren() { | 118 void OmniboxPopupContentsView::LayoutChildren() { |
| 118 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider(); | |
| 119 const int min_vertical_padding = theme_provider->GetDisplayProperty( | |
| 120 ThemeProperties::PROPERTY_OMNIBOX_DROPDOWN_MIN_TEXT_VERTICAL_PADDING); | |
| 121 | |
| 122 gfx::Rect contents_rect = GetContentsBounds(); | 119 gfx::Rect contents_rect = GetContentsBounds(); |
| 123 contents_rect.Inset( | 120 contents_rect.Inset(GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT)); |
| 124 0, views::NonClientFrameView::kClientEdgeThickness + min_vertical_padding, | 121 contents_rect.Inset(0, views::NonClientFrameView::kClientEdgeThickness, 0, 0); |
|
jonross
2015/09/14 15:27:10
Incorporate into OMNIBOX_DROPDOWN_TEXT?
Peter Kasting
2015/09/14 21:06:31
Not all callers want this inclusion.
jonross
2015/09/14 23:46:43
Acknowledged.
| |
| 125 0, min_vertical_padding); | |
| 126 | 122 |
| 127 // In the non-material dropdown, the colored/clickable regions within the | 123 // In the non-material dropdown, the colored/clickable regions within the |
| 128 // dropdown are only as wide as the location bar. In the material version, | 124 // dropdown are only as wide as the location bar. In the material version, |
| 129 // these are full width, and OmniboxResultView instead insets the icons/text | 125 // these are full width, and OmniboxResultView instead insets the icons/text |
| 130 // inside to be aligned with the location bar. | 126 // inside to be aligned with the location bar. |
| 131 if (!ui::MaterialDesignController::IsModeMaterial()) | 127 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 132 contents_rect.Inset(start_margin_, 0, end_margin_, 0); | 128 contents_rect.Inset(start_margin_, 0, end_margin_, 0); |
| 133 | 129 |
| 134 int top = contents_rect.y(); | 130 int top = contents_rect.y(); |
| 135 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 131 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 411 |
| 416 //////////////////////////////////////////////////////////////////////////////// | 412 //////////////////////////////////////////////////////////////////////////////// |
| 417 // OmniboxPopupContentsView, protected: | 413 // OmniboxPopupContentsView, protected: |
| 418 | 414 |
| 419 int OmniboxPopupContentsView::CalculatePopupHeight() { | 415 int OmniboxPopupContentsView::CalculatePopupHeight() { |
| 420 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 416 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 421 int popup_height = 0; | 417 int popup_height = 0; |
| 422 for (size_t i = 0; i < model_->result().size(); ++i) | 418 for (size_t i = 0; i < model_->result().size(); ++i) |
| 423 popup_height += child_at(i)->GetPreferredSize().height(); | 419 popup_height += child_at(i)->GetPreferredSize().height(); |
| 424 | 420 |
| 425 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider(); | |
| 426 const int min_text_vertical_padding = theme_provider->GetDisplayProperty( | |
| 427 ThemeProperties::PROPERTY_OMNIBOX_DROPDOWN_MIN_TEXT_VERTICAL_PADDING); | |
| 428 const int border_interior = theme_provider->GetDisplayProperty( | |
| 429 ThemeProperties::PROPERTY_OMNIBOX_DROPDOWN_BORDER_INTERIOR); | |
| 430 | |
| 431 // Add enough space on the top and bottom so it looks like there is the same | 421 // Add enough space on the top and bottom so it looks like there is the same |
| 432 // amount of space between the text and the popup border as there is in the | 422 // amount of space between the text and the popup border as there is in the |
| 433 // interior between each row of text. | 423 // interior between each row of text. |
| 434 // | 424 return popup_height + views::NonClientFrameView::kClientEdgeThickness + |
| 435 // The * 2 accounts for vertical padding used at the top and bottom. | 425 GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height() + |
| 436 return popup_height + | 426 bottom_shadow_->height() - |
| 437 views::NonClientFrameView::kClientEdgeThickness + // Top border. | 427 GetLayoutConstant(OMNIBOX_DROPDOWN_BORDER_INTERIOR); |
| 438 min_text_vertical_padding * 2 + // Padding. | |
| 439 bottom_shadow_->height() - border_interior; // Bottom border. | |
| 440 } | 428 } |
| 441 | 429 |
| 442 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( | 430 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( |
| 443 int model_index, | 431 int model_index, |
| 444 const gfx::FontList& font_list) { | 432 const gfx::FontList& font_list) { |
| 445 return new OmniboxResultView(this, model_index, location_bar_view_, | 433 return new OmniboxResultView(this, model_index, location_bar_view_, |
| 446 font_list); | 434 font_list); |
| 447 } | 435 } |
| 448 | 436 |
| 449 //////////////////////////////////////////////////////////////////////////////// | 437 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 465 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); | 453 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); |
| 466 } | 454 } |
| 467 | 455 |
| 468 // Bottom border. | 456 // Bottom border. |
| 469 canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(), | 457 canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(), |
| 470 width(), bottom_shadow_->height()); | 458 width(), bottom_shadow_->height()); |
| 471 } | 459 } |
| 472 | 460 |
| 473 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { | 461 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { |
| 474 gfx::Rect contents_bounds = GetContentsBounds(); | 462 gfx::Rect contents_bounds = GetContentsBounds(); |
| 475 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider(); | 463 const int interior = GetLayoutConstant(OMNIBOX_DROPDOWN_BORDER_INTERIOR); |
| 476 const int border_interior = theme_provider->GetDisplayProperty( | |
| 477 ThemeProperties::PROPERTY_OMNIBOX_DROPDOWN_BORDER_INTERIOR); | |
| 478 | |
| 479 contents_bounds.Inset(0, views::NonClientFrameView::kClientEdgeThickness, 0, | 464 contents_bounds.Inset(0, views::NonClientFrameView::kClientEdgeThickness, 0, |
| 480 bottom_shadow_->height() - border_interior); | 465 bottom_shadow_->height() - interior); |
| 481 | 466 |
| 482 ui::ClipTransformRecorder clip_transform_recorder(context); | 467 ui::ClipTransformRecorder clip_transform_recorder(context); |
| 483 clip_transform_recorder.ClipRect(contents_bounds); | 468 clip_transform_recorder.ClipRect(contents_bounds); |
| 484 { | 469 { |
| 485 ui::PaintRecorder recorder(context, size()); | 470 ui::PaintRecorder recorder(context, size()); |
| 486 SkColor background_color = result_view_at(0)->GetColor( | 471 SkColor background_color = result_view_at(0)->GetColor( |
| 487 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); | 472 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); |
| 488 recorder.canvas()->DrawColor(background_color); | 473 recorder.canvas()->DrawColor(background_color); |
| 489 } | 474 } |
| 490 View::PaintChildren(context); | 475 View::PaintChildren(context); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 size_t index = GetIndexForPoint(event.location()); | 525 size_t index = GetIndexForPoint(event.location()); |
| 541 if (!HasMatchAt(index)) | 526 if (!HasMatchAt(index)) |
| 542 return; | 527 return; |
| 543 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 528 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
| 544 GURL(), base::string16(), index); | 529 GURL(), base::string16(), index); |
| 545 } | 530 } |
| 546 | 531 |
| 547 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 532 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
| 548 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 533 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
| 549 } | 534 } |
| OLD | NEW |