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

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

Issue 10831253: Only compute LocationBarView::AvailableWidth as needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore max_edit_width naming. Created 8 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 // space, but never elide it any smaller than 150 px. 685 // space, but never elide it any smaller than 150 px.
686 static const int kMinElidedBubbleWidth = 150; 686 static const int kMinElidedBubbleWidth = 150;
687 static const double kMaxBubbleFraction = 0.5; 687 static const double kMaxBubbleFraction = 0.5;
688 const int total_padding = 688 const int total_padding =
689 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 689 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding;
690 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 690 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
691 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 691 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
692 entry_width -= (total_padding + ev_bubble_width); 692 entry_width -= (total_padding + ev_bubble_width);
693 } 693 }
694 694
695 int max_edit_width = location_entry_->GetMaxEditWidth(entry_width); 695 const int max_edit_width = location_entry_->GetMaxEditWidth(entry_width);
696 if (max_edit_width < 0) 696 if (max_edit_width < 0)
697 return; 697 return;
698 const int available_width = AvailableWidth(max_edit_width);
699 698
700 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; 699 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
701 selected_keyword_view_->SetVisible(show_selected_keyword); 700 selected_keyword_view_->SetVisible(show_selected_keyword);
702 keyword_hint_view_->SetVisible(show_keyword_hint); 701 keyword_hint_view_->SetVisible(show_keyword_hint);
703 if (show_selected_keyword) { 702 if (show_selected_keyword) {
704 if (selected_keyword_view_->keyword() != keyword) { 703 if (selected_keyword_view_->keyword() != keyword) {
705 selected_keyword_view_->SetKeyword(keyword); 704 selected_keyword_view_->SetKeyword(keyword);
706 const TemplateURL* template_url = 705 const TemplateURL* template_url =
707 TemplateURLServiceFactory::GetForProfile(profile_)-> 706 TemplateURLServiceFactory::GetForProfile(profile_)->
708 GetTemplateURLForKeyword(keyword); 707 GetTemplateURLForKeyword(keyword);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 offset = kEdgeThickness + 803 offset = kEdgeThickness +
805 (show_selected_keyword ? kBubbleHorizontalPadding : kEdgeEditPadding); 804 (show_selected_keyword ? kBubbleHorizontalPadding : kEdgeEditPadding);
806 } 805 }
807 806
808 // Now lay out the edit field and views that autocollapse to give it more 807 // Now lay out the edit field and views that autocollapse to give it more
809 // room. 808 // room.
810 gfx::Rect location_bounds(offset, location_y, entry_width, location_height); 809 gfx::Rect location_bounds(offset, location_y, entry_width, location_height);
811 if (show_selected_keyword) { 810 if (show_selected_keyword) {
812 selected_keyword_view_->SetBounds(0, location_y + kBubbleVerticalPadding, 811 selected_keyword_view_->SetBounds(0, location_y + kBubbleVerticalPadding,
813 0, selected_keyword_view_->GetPreferredSize().height()); 812 0, selected_keyword_view_->GetPreferredSize().height());
814 LayoutView(selected_keyword_view_, kItemEditPadding, available_width, 813 LayoutView(selected_keyword_view_, kItemEditPadding,
815 true, &location_bounds); 814 AvailableWidth(max_edit_width), true, &location_bounds);
816 location_bounds.set_x(selected_keyword_view_->visible() ? 815 location_bounds.set_x(selected_keyword_view_->visible() ?
817 (offset + selected_keyword_view_->width() + kItemEditPadding) : 816 (offset + selected_keyword_view_->width() + kItemEditPadding) :
818 (kEdgeThickness + kEdgeEditPadding)); 817 (kEdgeThickness + kEdgeEditPadding));
819 } else if (show_keyword_hint) { 818 } else if (show_keyword_hint) {
820 keyword_hint_view_->SetBounds(0, location_y, 0, location_height); 819 keyword_hint_view_->SetBounds(0, location_y, 0, location_height);
821 // Tricky: |entry_width| has already been enlarged by |kEditInternalSpace|. 820 // Tricky: |entry_width| has already been enlarged by |kEditInternalSpace|.
822 // But if we add a trailing view, it needs to have that enlargement be to 821 // But if we add a trailing view, it needs to have that enlargement be to
823 // its left. So we undo the enlargement, then include it in the padding for 822 // its left. So we undo the enlargement, then include it in the padding for
824 // the added view. 823 // the added view.
825 location_bounds.Inset(0, 0, kEditInternalSpace, 0); 824 location_bounds.Inset(0, 0, kEditInternalSpace, 0);
826 LayoutView(keyword_hint_view_, kItemEditPadding, available_width, false, 825 LayoutView(keyword_hint_view_, kItemEditPadding,
827 &location_bounds); 826 AvailableWidth(max_edit_width), false, &location_bounds);
828 if (!keyword_hint_view_->visible()) { 827 if (!keyword_hint_view_->visible()) {
829 // Put back the enlargement that we undid above. 828 // Put back the enlargement that we undid above.
830 location_bounds.Inset(0, 0, -kEditInternalSpace, 0); 829 location_bounds.Inset(0, 0, -kEditInternalSpace, 0);
831 } 830 }
832 } 831 }
833 832
834 // Layout out the suggested text view right aligned to the location 833 // Layout out the suggested text view right aligned to the location
835 // entry. Only show the suggested text if we can fit the text from one 834 // entry. Only show the suggested text if we can fit the text from one
836 // character before the end of the selection to the end of the text and the 835 // character before the end of the selection to the end of the text and the
837 // suggested text. If we can't it means either the suggested text is too big, 836 // suggested text. If we can't it means either the suggested text is too big,
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 } 1496 }
1498 1497
1499 void LocationBarView::CleanupFadeAnimation() { 1498 void LocationBarView::CleanupFadeAnimation() {
1500 // Since we're no longer animating we don't need our layer. 1499 // Since we're no longer animating we don't need our layer.
1501 SetPaintToLayer(false); 1500 SetPaintToLayer(false);
1502 // Bubble labels don't need a transparent background anymore. 1501 // Bubble labels don't need a transparent background anymore.
1503 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1502 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1504 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1503 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1505 } 1504 }
1506 #endif // USE_AURA 1505 #endif // USE_AURA
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698