Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1455193003: Draw popup window toolbars as only containing a location bar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arbitrary_heights
Patch Set: Glass cleanups Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return base::i18n::IsRTL() ? 1 : 0; 109 return base::i18n::IsRTL() ? 1 : 0;
110 } 110 }
111 111
112 } // namespace 112 } // namespace
113 113
114 114
115 // LocationBarView ----------------------------------------------------------- 115 // LocationBarView -----------------------------------------------------------
116 116
117 // static 117 // static
118 118
119 // Thickness of the edges of the omnibox background images, for popup windows.
120 const int kPopupEdgeThickness = 1;
121
122 const char LocationBarView::kViewClassName[] = "LocationBarView"; 119 const char LocationBarView::kViewClassName[] = "LocationBarView";
123 120
124 LocationBarView::LocationBarView(Browser* browser, 121 LocationBarView::LocationBarView(Browser* browser,
125 Profile* profile, 122 Profile* profile,
126 CommandUpdater* command_updater, 123 CommandUpdater* command_updater,
127 Delegate* delegate, 124 Delegate* delegate,
128 bool is_popup_mode) 125 bool is_popup_mode)
129 : LocationBar(profile), 126 : LocationBar(profile),
130 ChromeOmniboxEditController(command_updater), 127 ChromeOmniboxEditController(command_updater),
131 browser_(browser), 128 browser_(browser),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 164 }
168 165
169 //////////////////////////////////////////////////////////////////////////////// 166 ////////////////////////////////////////////////////////////////////////////////
170 // LocationBarView, public: 167 // LocationBarView, public:
171 168
172 void LocationBarView::Init() { 169 void LocationBarView::Init() {
173 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're 170 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're
174 // not prepared for that. 171 // not prepared for that.
175 DCHECK(GetWidget()); 172 DCHECK(GetWidget());
176 173
177 if (is_popup_mode_) { 174 if (!ui::MaterialDesignController::IsModeMaterial()) {
178 const int kOmniboxPopupBorderImages[] = 175 if (is_popup_mode_) {
179 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); 176 const int kOmniboxPopupBorderImages[] =
180 border_painter_.reset( 177 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW);
181 views::Painter::CreateImageGridPainter(kOmniboxPopupBorderImages)); 178 border_painter_.reset(
182 } else if (!ui::MaterialDesignController::IsModeMaterial()) { 179 views::Painter::CreateImageGridPainter(kOmniboxPopupBorderImages));
183 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 180 } else {
184 const gfx::Insets omnibox_border_insets(14, 9, 14, 9); 181 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
185 border_painter_.reset(views::Painter::CreateImagePainter( 182 const gfx::Insets omnibox_border_insets(14, 9, 14, 9);
186 *rb.GetImageSkiaNamed(IDR_OMNIBOX_BORDER), omnibox_border_insets)); 183 border_painter_.reset(views::Painter::CreateImagePainter(
184 *rb.GetImageSkiaNamed(IDR_OMNIBOX_BORDER), omnibox_border_insets));
185 }
187 } 186 }
188 187
189 location_icon_view_ = new LocationIconView(this); 188 location_icon_view_ = new LocationIconView(this);
190 location_icon_view_->set_drag_controller(this); 189 location_icon_view_->set_drag_controller(this);
191 AddChildView(location_icon_view_); 190 AddChildView(location_icon_view_);
192 191
193 // Determine the main font. 192 // Determine the main font.
194 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( 193 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList(
195 ResourceBundle::BaseFont); 194 ResourceBundle::BaseFont);
196 const int current_font_size = font_list.GetFontSize(); 195 const int current_font_size = font_list.GetFontSize();
197 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); 196 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE);
198 if (current_font_size != desired_font_size) { 197 if (current_font_size != desired_font_size) {
199 font_list = 198 font_list =
200 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); 199 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size);
201 } 200 }
202 // Shrink large fonts to make them fit. 201 // Shrink large fonts to make them fit.
203 // TODO(pkasting): Stretch the location bar instead in this case. 202 // TODO(pkasting): Stretch the location bar instead in this case.
204 const int location_height = GetInternalHeight(true); 203 const int location_height = GetInternalHeight(true);
205 font_list = font_list.DeriveWithHeightUpperBound(location_height); 204 font_list = font_list.DeriveWithHeightUpperBound(location_height);
206 205
207 // Determine the font for use inside the bubbles. The bubble background 206 // Determine the font for use inside the bubbles. The bubble background
208 // images have 1 px thick edges, which we don't want to overlap. 207 // images have 1 px thick edges, which we don't want to overlap.
209 const int kBubbleInteriorVerticalPadding = 208 const int kBubbleInteriorVerticalPadding =
210 ui::MaterialDesignController::IsModeMaterial() ? 2 : 1; 209 ui::MaterialDesignController::IsModeMaterial() ? 2 : 1;
211 const int bubble_padding = 210 const int bubble_padding =
212 GetVerticalEdgeThickness() + 211 GetEdgeThickness() +
213 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + 212 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) +
214 kBubbleInteriorVerticalPadding; 213 kBubbleInteriorVerticalPadding;
215 const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2); 214 const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2);
216 gfx::FontList bubble_font_list = 215 gfx::FontList bubble_font_list =
217 font_list.DeriveWithHeightUpperBound(bubble_height); 216 font_list.DeriveWithHeightUpperBound(bubble_height);
218 217
219 const SkColor background_color = GetColor(LocationBarView::BACKGROUND); 218 const SkColor background_color = GetColor(LocationBarView::BACKGROUND);
220 const SkColor ev_text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); 219 const SkColor ev_text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER);
221 ev_bubble_view_ = 220 ev_bubble_view_ =
222 new EVBubbleView(bubble_font_list, ev_text_color, background_color, this); 221 new EVBubbleView(bubble_font_list, ev_text_color, background_color, this);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 return omnibox_view_->model()->has_focus(); 513 return omnibox_view_->model()->has_focus();
515 } 514 }
516 515
517 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { 516 void LocationBarView::GetAccessibleState(ui::AXViewState* state) {
518 state->role = ui::AX_ROLE_GROUP; 517 state->role = ui::AX_ROLE_GROUP;
519 } 518 }
520 519
521 gfx::Size LocationBarView::GetPreferredSize() const { 520 gfx::Size LocationBarView::GetPreferredSize() const {
522 // Compute minimum height. 521 // Compute minimum height.
523 gfx::Size min_size; 522 gfx::Size min_size;
524 // For non-material the size of the asset determines the size of the 523 if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) {
525 // LocationBarView. 524 const int height = GetLayoutConstant(LOCATION_BAR_HEIGHT);
526 if (ui::MaterialDesignController::IsModeMaterial()) 525 const int edge_thickness = views::NonClientFrameView::kClientEdgeThickness;
527 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); 526 min_size.set_height(height - (is_popup_mode_ ? (2 * edge_thickness) : 0));
528 else 527 } else {
529 min_size = border_painter_->GetMinimumSize(); 528 min_size = border_painter_->GetMinimumSize();
529 }
530 530
531 if (!IsInitialized()) 531 if (!IsInitialized())
532 return min_size; 532 return min_size;
533 533
534 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 534 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
535 535
536 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 536 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
537 537
538 // Compute width of omnibox-leading content. 538 // Compute width of omnibox-leading content.
539 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 539 const int edge_thickness = GetEdgeThickness();
540 int leading_width = horizontal_edge_thickness; 540 int leading_width = edge_thickness;
541 if (ShouldShowKeywordBubble()) { 541 if (ShouldShowKeywordBubble()) {
542 // The selected keyword view can collapse completely. 542 // The selected keyword view can collapse completely.
543 } else if (ShouldShowEVBubble()) { 543 } else if (ShouldShowEVBubble()) {
544 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + 544 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
545 ev_bubble_view_->GetMinimumSizeForLabelText( 545 ev_bubble_view_->GetMinimumSizeForLabelText(
546 GetToolbarModel()->GetEVCertName()).width(); 546 GetToolbarModel()->GetEVCertName()).width();
547 } else { 547 } else {
548 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 548 leading_width += padding + location_icon_view_->GetMinimumSize().width();
549 } 549 }
550 550
551 // Compute width of omnibox-trailing content. 551 // Compute width of omnibox-trailing content.
552 int trailing_width = horizontal_edge_thickness; 552 int trailing_width = edge_thickness;
553 trailing_width += IncrementalMinimumWidth(star_view_) + 553 trailing_width += IncrementalMinimumWidth(star_view_) +
554 IncrementalMinimumWidth(translate_icon_view_) + 554 IncrementalMinimumWidth(translate_icon_view_) +
555 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 555 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
556 IncrementalMinimumWidth(save_credit_card_icon_view_) + 556 IncrementalMinimumWidth(save_credit_card_icon_view_) +
557 IncrementalMinimumWidth(manage_passwords_icon_view_) + 557 IncrementalMinimumWidth(manage_passwords_icon_view_) +
558 IncrementalMinimumWidth(zoom_view_); 558 IncrementalMinimumWidth(zoom_view_);
559 for (PageActionViews::const_iterator i(page_action_views_.begin()); 559 for (PageActionViews::const_iterator i(page_action_views_.begin());
560 i != page_action_views_.end(); ++i) 560 i != page_action_views_.end(); ++i)
561 trailing_width += IncrementalMinimumWidth((*i)); 561 trailing_width += IncrementalMinimumWidth((*i));
562 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 562 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
563 i != content_setting_views_.end(); ++i) 563 i != content_setting_views_.end(); ++i)
564 trailing_width += IncrementalMinimumWidth((*i)); 564 trailing_width += IncrementalMinimumWidth((*i));
565 565
566 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + 566 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() +
567 2 * padding - omnibox_view_->GetInsets().width() + 567 2 * padding - omnibox_view_->GetInsets().width() +
568 trailing_width); 568 trailing_width);
569 return min_size; 569 return min_size;
570 } 570 }
571 571
572 void LocationBarView::Layout() { 572 void LocationBarView::Layout() {
573 if (!IsInitialized()) 573 if (!IsInitialized())
574 return; 574 return;
575 575
576 selected_keyword_view_->SetVisible(false); 576 selected_keyword_view_->SetVisible(false);
577 location_icon_view_->SetVisible(false); 577 location_icon_view_->SetVisible(false);
578 ev_bubble_view_->SetVisible(false); 578 ev_bubble_view_->SetVisible(false);
579 keyword_hint_view_->SetVisible(false); 579 keyword_hint_view_->SetVisible(false);
580 580
581 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 581 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
582 const int edge_thickness = GetEdgeThickness();
582 int trailing_edge_item_padding = 0; 583 int trailing_edge_item_padding = 0;
583 if (!ui::MaterialDesignController::IsModeMaterial()) { 584 if (!ui::MaterialDesignController::IsModeMaterial()) {
584 trailing_edge_item_padding = item_padding - GetHorizontalEdgeThickness() - 585 trailing_edge_item_padding =
585 omnibox_view_->GetInsets().right(); 586 item_padding - edge_thickness - omnibox_view_->GetInsets().right();
586 } 587 }
587 588
588 LocationBarLayout leading_decorations( 589 LocationBarLayout leading_decorations(
589 LocationBarLayout::LEFT_EDGE, item_padding, 590 LocationBarLayout::LEFT_EDGE, item_padding,
590 item_padding - omnibox_view_->GetInsets().left() - 591 item_padding - omnibox_view_->GetInsets().left() -
591 GetEditLeadingInternalSpace()); 592 GetEditLeadingInternalSpace());
592 LocationBarLayout trailing_decorations( 593 LocationBarLayout trailing_decorations(
593 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding); 594 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding);
594 595
595 const base::string16 keyword(omnibox_view_->model()->keyword()); 596 const base::string16 keyword(omnibox_view_->model()->keyword());
596 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 597 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
597 // to position our child views in this case, because other things may be 598 // to position our child views in this case, because other things may be
598 // positioned relative to them (e.g. the "bookmark added" bubble if the user 599 // positioned relative to them (e.g. the "bookmark added" bubble if the user
599 // hits ctrl-d). 600 // hits ctrl-d).
600 const int bubble_vertical_padding = 601 const int bubble_vertical_padding =
601 GetVerticalEdgeThickness() + 602 edge_thickness + GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING);
602 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING);
603 const int bubble_height = 603 const int bubble_height =
604 std::max(height() - (bubble_vertical_padding * 2), 0); 604 std::max(height() - (bubble_vertical_padding * 2), 0);
605 const int bubble_horizontal_padding = 605 const int bubble_horizontal_padding =
606 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); 606 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING);
607 const int location_height = GetInternalHeight(false); 607 const int location_height = GetInternalHeight(false);
608 const int vertical_padding = VerticalPadding(); 608 const int vertical_padding = VerticalPadding();
609 if (ShouldShowKeywordBubble()) { 609 if (ShouldShowKeywordBubble()) {
610 leading_decorations.AddDecoration(bubble_vertical_padding, bubble_height, 610 leading_decorations.AddDecoration(bubble_vertical_padding, bubble_height,
611 true, 0, bubble_horizontal_padding, 611 true, 0, bubble_horizontal_padding,
612 item_padding, selected_keyword_view_); 612 item_padding, selected_keyword_view_);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 if (!keyword.empty() && omnibox_view_->model()->is_keyword_hint() && 683 if (!keyword.empty() && omnibox_view_->model()->is_keyword_hint() &&
684 !omnibox_view_->IsImeComposing()) { 684 !omnibox_view_->IsImeComposing()) {
685 trailing_decorations.AddDecoration(vertical_padding, location_height, true, 685 trailing_decorations.AddDecoration(vertical_padding, location_height, true,
686 0, item_padding, item_padding, 686 0, item_padding, item_padding,
687 keyword_hint_view_); 687 keyword_hint_view_);
688 if (keyword_hint_view_->keyword() != keyword) 688 if (keyword_hint_view_->keyword() != keyword)
689 keyword_hint_view_->SetKeyword(keyword); 689 keyword_hint_view_->SetKeyword(keyword);
690 } 690 }
691 691
692 // Perform layout. 692 // Perform layout.
693 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 693 int full_width = width() - (2 * edge_thickness);
694 int full_width = width() - (2 * horizontal_edge_thickness);
695 694
696 int entry_width = full_width; 695 int entry_width = full_width;
697 leading_decorations.LayoutPass1(&entry_width); 696 leading_decorations.LayoutPass1(&entry_width);
698 trailing_decorations.LayoutPass1(&entry_width); 697 trailing_decorations.LayoutPass1(&entry_width);
699 leading_decorations.LayoutPass2(&entry_width); 698 leading_decorations.LayoutPass2(&entry_width);
700 trailing_decorations.LayoutPass2(&entry_width); 699 trailing_decorations.LayoutPass2(&entry_width);
701 700
702 int location_needed_width = omnibox_view_->GetTextWidth(); 701 int location_needed_width = omnibox_view_->GetTextWidth();
703 int available_width = entry_width - location_needed_width; 702 int available_width = entry_width - location_needed_width;
704 // The bounds must be wide enough for all the decorations to fit. 703 // The bounds must be wide enough for all the decorations to fit.
705 gfx::Rect location_bounds(horizontal_edge_thickness, vertical_padding, 704 gfx::Rect location_bounds(edge_thickness, vertical_padding,
706 std::max(full_width, full_width - entry_width), 705 std::max(full_width, full_width - entry_width),
707 location_height); 706 location_height);
708 leading_decorations.LayoutPass3(&location_bounds, &available_width); 707 leading_decorations.LayoutPass3(&location_bounds, &available_width);
709 trailing_decorations.LayoutPass3(&location_bounds, &available_width); 708 trailing_decorations.LayoutPass3(&location_bounds, &available_width);
710 709
711 // Layout out the suggested text view right aligned to the location 710 // Layout out the suggested text view right aligned to the location
712 // entry. Only show the suggested text if we can fit the text from one 711 // entry. Only show the suggested text if we can fit the text from one
713 // character before the end of the selection to the end of the text and the 712 // character before the end of the selection to the end of the text and the
714 // suggested text. If we can't it means either the suggested text is too big, 713 // suggested text. If we can't it means either the suggested text is too big,
715 // or the user has scrolled. 714 // or the user has scrolled.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 x = entry_width - width; 780 x = entry_width - width;
782 location_bounds.set_width(x); 781 location_bounds.set_width(x);
783 ime_inline_autocomplete_view_->SetBounds( 782 ime_inline_autocomplete_view_->SetBounds(
784 location_bounds.right(), location_bounds.y(), 783 location_bounds.right(), location_bounds.y(),
785 std::min(width, entry_width), location_bounds.height()); 784 std::min(width, entry_width), location_bounds.height());
786 } 785 }
787 omnibox_view_->SetBoundsRect(location_bounds); 786 omnibox_view_->SetBoundsRect(location_bounds);
788 } 787 }
789 788
790 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 789 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
791 if (!ui::MaterialDesignController::IsModeMaterial()) 790 if (ui::MaterialDesignController::IsModeMaterial()) {
792 return; 791 RefreshLocationIcon();
793 792 if (!is_popup_mode_) {
794 RefreshLocationIcon(); 793 set_background(new BackgroundWith1PxBorder(
795 set_background(new BackgroundWith1PxBorder( 794 GetColor(BACKGROUND), SkColorSetARGB(0x4D, 0x00, 0x00, 0x00)));
796 GetColor(BACKGROUND), SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), 795 }
797 is_popup_mode_)); 796 }
798 } 797 }
799 798
800 void LocationBarView::Update(const WebContents* contents) { 799 void LocationBarView::Update(const WebContents* contents) {
801 RefreshContentSettingViews(); 800 RefreshContentSettingViews();
802 RefreshZoomView(); 801 RefreshZoomView();
803 RefreshPageActionViews(); 802 RefreshPageActionViews();
804 RefreshTranslateIcon(); 803 RefreshTranslateIcon();
805 RefreshSaveCreditCardIconView(); 804 RefreshSaveCreditCardIconView();
806 RefreshManagePasswordsIconView(); 805 RefreshManagePasswordsIconView();
807 content::WebContents* web_contents_for_sub_views = 806 content::WebContents* web_contents_for_sub_views =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 843
845 //////////////////////////////////////////////////////////////////////////////// 844 ////////////////////////////////////////////////////////////////////////////////
846 // LocationBarView, private: 845 // LocationBarView, private:
847 846
848 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { 847 int LocationBarView::IncrementalMinimumWidth(views::View* view) const {
849 return view->visible() ? 848 return view->visible() ?
850 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + 849 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) +
851 view->GetMinimumSize().width()) : 0; 850 view->GetMinimumSize().width()) : 0;
852 } 851 }
853 852
854 int LocationBarView::GetHorizontalEdgeThickness() const { 853 int LocationBarView::GetEdgeThickness() const {
855 // In maximized popup mode, there isn't any edge. 854 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
856 return (is_popup_mode_ && browser_ && browser_->window() &&
857 browser_->window()->IsMaximized()) ?
858 0 : GetVerticalEdgeThickness();
859 }
860
861 int LocationBarView::GetVerticalEdgeThickness() const {
862 return is_popup_mode_ ? kPopupEdgeThickness
863 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
864 } 855 }
865 856
866 int LocationBarView::VerticalPadding() const { 857 int LocationBarView::VerticalPadding() const {
867 return is_popup_mode_ ? 858 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
868 kPopupEdgeThickness : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
869 } 859 }
870 860
871 void LocationBarView::RefreshLocationIcon() { 861 void LocationBarView::RefreshLocationIcon() {
872 // |omnibox_view_| may not be ready yet if Init() has not been called. The 862 // |omnibox_view_| may not be ready yet if Init() has not been called. The
873 // icon will be set soon by OnChanged(). 863 // icon will be set soon by OnChanged().
874 if (!omnibox_view_) 864 if (!omnibox_view_)
875 return; 865 return;
876 866
877 if (ui::MaterialDesignController::IsModeMaterial()) { 867 if (ui::MaterialDesignController::IsModeMaterial()) {
878 location_icon_view_->SetImage(gfx::CreateVectorIcon( 868 location_icon_view_->SetImage(gfx::CreateVectorIcon(
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1259
1270 void LocationBarView::OnFocus() { 1260 void LocationBarView::OnFocus() {
1271 // Explicitly focus the omnibox so a focus ring will be displayed around it on 1261 // Explicitly focus the omnibox so a focus ring will be displayed around it on
1272 // Windows. 1262 // Windows.
1273 omnibox_view_->SetFocus(); 1263 omnibox_view_->SetFocus();
1274 } 1264 }
1275 1265
1276 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 1266 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
1277 View::OnPaint(canvas); 1267 View::OnPaint(canvas);
1278 1268
1279 if (ui::MaterialDesignController::IsModeMaterial()) 1269 if (ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_)
1280 return; // The background and border are painted by our Background. 1270 return; // The background and border are painted by our Background.
1281 1271
1282 // Fill the location bar background color behind the border. Parts of the 1272 // Fill the location bar background color behind the border. Parts of the
1283 // border images are meant to rest atop the toolbar background and parts atop 1273 // border images are meant to rest atop the toolbar background and parts atop
1284 // the omnibox background, so we can't just blindly fill our entire bounds. 1274 // the omnibox background, so we can't just blindly fill our entire bounds.
1285 gfx::Rect bounds(GetContentsBounds()); 1275 gfx::Rect bounds(GetContentsBounds());
1286 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); 1276 const int edge_thickness = GetEdgeThickness();
1277 bounds.Inset(edge_thickness, edge_thickness);
1287 SkColor color(GetColor(BACKGROUND)); 1278 SkColor color(GetColor(BACKGROUND));
1288 if (is_popup_mode_) { 1279 if (is_popup_mode_) {
1289 canvas->FillRect(bounds, color); 1280 canvas->FillRect(bounds, color);
1290 } else { 1281 } else {
1291 SkPaint paint; 1282 SkPaint paint;
1292 paint.setStyle(SkPaint::kFill_Style); 1283 paint.setStyle(SkPaint::kFill_Style);
1293 paint.setColor(color); 1284 paint.setColor(color);
1294 const int kBorderCornerRadius = 2; 1285 const int kBorderCornerRadius = 2;
1295 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1286 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1296 } 1287 }
1297 1288
1298 // The border itself will be drawn in PaintChildren() since it includes an 1289 // The border itself will be drawn in PaintChildren() since it includes an
1299 // inner shadow which should be drawn over the contents. 1290 // inner shadow which should be drawn over the contents.
1300 } 1291 }
1301 1292
1302 void LocationBarView::PaintChildren(const ui::PaintContext& context) { 1293 void LocationBarView::PaintChildren(const ui::PaintContext& context) {
1303 View::PaintChildren(context); 1294 View::PaintChildren(context);
1304 1295
1305 ui::PaintRecorder recorder(context, size()); 1296 ui::PaintRecorder recorder(context, size());
1306 1297
1307 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need 1298 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need
1308 // the focus rect to appear on top of children we paint here rather than 1299 // the focus rect to appear on top of children we paint here rather than
1309 // OnPaint(). 1300 // OnPaint().
1310 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. 1301 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color.
1311 if (show_focus_rect_ && HasFocus()) 1302 if (show_focus_rect_ && HasFocus())
1312 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); 1303 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds());
1313 1304
1314 if (ui::MaterialDesignController::IsModeMaterial()) 1305 if (!ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) {
1315 return; // The background and border are painted by our Background. 1306 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
1316 1307 GetContentsBounds());
1317 // Maximized popup windows don't draw the horizontal edges. We implement this 1308 }
1318 // by simply expanding the paint area outside the view by the edge thickness.
1319 gfx::Rect border_rect(GetContentsBounds());
1320 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0))
1321 border_rect.Inset(-kPopupEdgeThickness, 0);
1322
1323 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
1324 border_rect);
1325 } 1309 }
1326 1310
1327 //////////////////////////////////////////////////////////////////////////////// 1311 ////////////////////////////////////////////////////////////////////////////////
1328 // LocationBarView, private views::DragController implementation: 1312 // LocationBarView, private views::DragController implementation:
1329 1313
1330 void LocationBarView::WriteDragDataForView(views::View* sender, 1314 void LocationBarView::WriteDragDataForView(views::View* sender,
1331 const gfx::Point& press_pt, 1315 const gfx::Point& press_pt,
1332 OSExchangeData* data) { 1316 OSExchangeData* data) {
1333 DCHECK_NE(GetDragOperationsForView(sender, press_pt), 1317 DCHECK_NE(GetDragOperationsForView(sender, press_pt),
1334 ui::DragDropTypes::DRAG_NONE); 1318 ui::DragDropTypes::DRAG_NONE);
(...skipping 22 matching lines...) Expand all
1357 1341
1358 bool LocationBarView::CanStartDragForView(View* sender, 1342 bool LocationBarView::CanStartDragForView(View* sender,
1359 const gfx::Point& press_pt, 1343 const gfx::Point& press_pt,
1360 const gfx::Point& p) { 1344 const gfx::Point& p) {
1361 return true; 1345 return true;
1362 } 1346 }
1363 1347
1364 //////////////////////////////////////////////////////////////////////////////// 1348 ////////////////////////////////////////////////////////////////////////////////
1365 // LocationBarView, private gfx::AnimationDelegate implementation: 1349 // LocationBarView, private gfx::AnimationDelegate implementation:
1366 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { 1350 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) {
1367 browser_->window()->ToolbarSizeChanged(true); 1351 GetWidget()->non_client_view()->Layout();
1368 } 1352 }
1369 1353
1370 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { 1354 void LocationBarView::AnimationEnded(const gfx::Animation* animation) {
1371 browser_->window()->ToolbarSizeChanged(false); 1355 AnimationProgressed(animation);
1372 } 1356 }
1373 1357
1374 //////////////////////////////////////////////////////////////////////////////// 1358 ////////////////////////////////////////////////////////////////////////////////
1375 // LocationBarView, private OmniboxEditController implementation: 1359 // LocationBarView, private OmniboxEditController implementation:
1376 1360
1377 void LocationBarView::OnChanged() { 1361 void LocationBarView::OnChanged() {
1378 RefreshLocationIcon(); 1362 RefreshLocationIcon();
1379 location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty()); 1363 location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty());
1380 1364
1381 Layout(); 1365 Layout();
(...skipping 23 matching lines...) Expand all
1405 // LocationBarView, private TemplateURLServiceObserver implementation: 1389 // LocationBarView, private TemplateURLServiceObserver implementation:
1406 1390
1407 void LocationBarView::OnTemplateURLServiceChanged() { 1391 void LocationBarView::OnTemplateURLServiceChanged() {
1408 template_url_service_->RemoveObserver(this); 1392 template_url_service_->RemoveObserver(this);
1409 template_url_service_ = NULL; 1393 template_url_service_ = NULL;
1410 // If the browser is no longer active, let's not show the info bubble, as this 1394 // If the browser is no longer active, let's not show the info bubble, as this
1411 // would make the browser the active window again. 1395 // would make the browser the active window again.
1412 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1396 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1413 ShowFirstRunBubble(); 1397 ShowFirstRunBubble();
1414 } 1398 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/toolbar/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698