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

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

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More compile fix for ToT Created 6 years, 7 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
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/keyword_hint_view.h" 5 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 int message_id = is_extension_keyword ? 58 int message_id = is_extension_keyword ?
59 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; 59 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT;
60 const base::string16 keyword_hint = l10n_util::GetStringFUTF16( 60 const base::string16 keyword_hint = l10n_util::GetStringFUTF16(
61 message_id, base::string16(), short_name, &content_param_offsets); 61 message_id, base::string16(), short_name, &content_param_offsets);
62 DCHECK_EQ(2U, content_param_offsets.size()); 62 DCHECK_EQ(2U, content_param_offsets.size());
63 leading_label_->SetText( 63 leading_label_->SetText(
64 keyword_hint.substr(0, content_param_offsets.front())); 64 keyword_hint.substr(0, content_param_offsets.front()));
65 trailing_label_->SetText(keyword_hint.substr(content_param_offsets.front())); 65 trailing_label_->SetText(keyword_hint.substr(content_param_offsets.front()));
66 } 66 }
67 67
68 gfx::Size KeywordHintView::GetPreferredSize() { 68 gfx::Size KeywordHintView::GetPreferredSize() const {
69 // Height will be ignored by the LocationBarView. 69 // Height will be ignored by the LocationBarView.
70 return gfx::Size(leading_label_->GetPreferredSize().width() + 70 return gfx::Size(leading_label_->GetPreferredSize().width() +
71 tab_image_->GetPreferredSize().width() + 71 tab_image_->GetPreferredSize().width() +
72 trailing_label_->GetPreferredSize().width(), 72 trailing_label_->GetPreferredSize().width(),
73 0); 73 0);
74 } 74 }
75 75
76 gfx::Size KeywordHintView::GetMinimumSize() { 76 gfx::Size KeywordHintView::GetMinimumSize() const {
77 // Height will be ignored by the LocationBarView. 77 // Height will be ignored by the LocationBarView.
78 return tab_image_->GetPreferredSize(); 78 return tab_image_->GetPreferredSize();
79 } 79 }
80 80
81 void KeywordHintView::Layout() { 81 void KeywordHintView::Layout() {
82 int tab_width = tab_image_->GetPreferredSize().width(); 82 int tab_width = tab_image_->GetPreferredSize().width();
83 bool show_labels = (width() != tab_width); 83 bool show_labels = (width() != tab_width);
84 gfx::Size leading_size(leading_label_->GetPreferredSize()); 84 gfx::Size leading_size(leading_label_->GetPreferredSize());
85 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0, 85 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0,
86 height()); 86 height());
87 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width, 87 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width,
88 height()); 88 height());
89 gfx::Size trailing_size(trailing_label_->GetPreferredSize()); 89 gfx::Size trailing_size(trailing_label_->GetPreferredSize());
90 trailing_label_->SetBounds(tab_image_->bounds().right(), 0, 90 trailing_label_->SetBounds(tab_image_->bounds().right(), 0,
91 show_labels ? trailing_size.width() : 0, 91 show_labels ? trailing_size.width() : 0,
92 height()); 92 height());
93 } 93 }
94 94
95 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, 95 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list,
96 SkColor text_color, 96 SkColor text_color,
97 SkColor background_color) { 97 SkColor background_color) {
98 views::Label* label = new views::Label(base::string16(), font_list); 98 views::Label* label = new views::Label(base::string16(), font_list);
99 label->SetEnabledColor(text_color); 99 label->SetEnabledColor(text_color);
100 label->SetBackgroundColor(background_color); 100 label->SetBackgroundColor(background_color);
101 AddChildView(label); 101 AddChildView(label);
102 return label; 102 return label;
103 } 103 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/keyword_hint_view.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698