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/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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 void LocationBarView::Init() { | 175 void LocationBarView::Init() { |
176 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 176 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
177 if (mode_ == POPUP) { | 177 if (mode_ == POPUP) { |
178 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); | 178 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); |
179 } else { | 179 } else { |
180 // Use a larger version of the system font. | 180 // Use a larger version of the system font. |
181 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); | 181 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); |
182 } | 182 } |
183 | 183 |
184 // If this makes the font too big, try to make it smaller so it will fit. | 184 // If this makes the font too big, try to make it smaller so it will fit. |
185 const int height = GetHeight(); | 185 const int height = GetInternalHeight(true); |
186 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) | 186 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) |
187 font_ = font_.DeriveFont(-1); | 187 font_ = font_.DeriveFont(-1); |
188 | 188 |
189 location_icon_view_ = new LocationIconView(this); | 189 location_icon_view_ = new LocationIconView(this); |
190 AddChildView(location_icon_view_); | 190 AddChildView(location_icon_view_); |
191 location_icon_view_->SetVisible(true); | 191 location_icon_view_->SetVisible(true); |
192 location_icon_view_->set_drag_controller(this); | 192 location_icon_view_->set_drag_controller(this); |
193 | 193 |
194 ev_bubble_view_ = | 194 ev_bubble_view_ = |
195 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, | 195 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 519 |
520 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. | 520 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. |
521 CHECK(location_icon_view_); | 521 CHECK(location_icon_view_); |
522 | 522 |
523 // TODO(sky): baseline layout. | 523 // TODO(sky): baseline layout. |
524 int location_y = kVerticalEdgeThickness; | 524 int location_y = kVerticalEdgeThickness; |
525 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 525 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
526 // to position our child views in this case, because other things may be | 526 // to position our child views in this case, because other things may be |
527 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 527 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
528 // hits ctrl-d). | 528 // hits ctrl-d). |
529 int location_height = std::max(height() - (kVerticalEdgeThickness * 2), 0); | 529 int location_height = GetInternalHeight(false); |
530 | 530 |
531 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the | 531 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the |
532 // omnibox' parent, so there isn't any edge to account for at all. | 532 // omnibox' parent, so there isn't any edge to account for at all. |
533 const int kEdgeThickness = (mode_ == NORMAL) ? | 533 const int kEdgeThickness = (mode_ == NORMAL) ? |
534 kNormalHorizontalEdgeThickness : 0; | 534 kNormalHorizontalEdgeThickness : 0; |
535 // The edit has 1 px of horizontal whitespace inside it before the text. | 535 // The edit has 1 px of horizontal whitespace inside it before the text. |
536 const int kEditInternalSpace = 1; | 536 const int kEditInternalSpace = 1; |
537 // The space between an item and the edit is the normal item space, minus the | 537 // The space between an item and the edit is the normal item space, minus the |
538 // edit's built-in space (so the apparent space will be the same). | 538 // edit's built-in space (so the apparent space will be the same). |
539 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; | 539 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 void LocationBarView::Observe(int type, | 1286 void LocationBarView::Observe(int type, |
1287 const content::NotificationSource& source, | 1287 const content::NotificationSource& source, |
1288 const content::NotificationDetails& details) { | 1288 const content::NotificationDetails& details) { |
1289 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 1289 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
1290 std::string* name = content::Details<std::string>(details).ptr(); | 1290 std::string* name = content::Details<std::string>(details).ptr(); |
1291 if (*name == prefs::kEditBookmarksEnabled) | 1291 if (*name == prefs::kEditBookmarksEnabled) |
1292 Update(NULL); | 1292 Update(NULL); |
1293 } | 1293 } |
1294 } | 1294 } |
1295 | 1295 |
1296 int LocationBarView::GetHeight() { | 1296 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
1297 return std::max( | 1297 int total_height = |
1298 GetPreferredSize().height() - (kVerticalEdgeThickness * 2), 0); | 1298 use_preferred_size ? GetPreferredSize().height() : height(); |
| 1299 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); |
1299 } | 1300 } |
1300 | 1301 |
1301 #if defined(OS_WIN) || defined(USE_AURA) | 1302 #if defined(OS_WIN) || defined(USE_AURA) |
1302 bool LocationBarView::HasValidSuggestText() const { | 1303 bool LocationBarView::HasValidSuggestText() const { |
1303 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1304 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1304 !suggested_text_view_->text().empty(); | 1305 !suggested_text_view_->text().empty(); |
1305 } | 1306 } |
1306 | 1307 |
1307 #if !defined(USE_AURA) | 1308 #if !defined(USE_AURA) |
1308 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1309 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
1309 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1310 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
1310 } | 1311 } |
1311 #endif | 1312 #endif |
1312 #endif | 1313 #endif |
OLD | NEW |