OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/chromeos/compact_navigation_bar.h" | 5 #include "chrome/browser/chromeos/compact_navigation_bar.h" |
6 | 6 |
7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/theme_provider.h" | 9 #include "app/theme_provider.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Draw this much white around the URL bar to make it look larger than it | 33 // Draw this much white around the URL bar to make it look larger than it |
34 // actually is. | 34 // actually is. |
35 static const int kURLPadding = 2; | 35 static const int kURLPadding = 2; |
36 | 36 |
37 CompactNavigationBar::CompactNavigationBar(Browser* browser) | 37 CompactNavigationBar::CompactNavigationBar(Browser* browser) |
38 : browser_(browser), | 38 : browser_(browser), |
39 initialized_(false) { | 39 initialized_(false) { |
40 } | 40 } |
41 | 41 |
42 CompactNavigationBar::~CompactNavigationBar() { | 42 CompactNavigationBar::~CompactNavigationBar() { |
43 location_entry_view_->Detach(); | 43 if (location_entry_view_->native_view()) |
| 44 location_entry_view_->Detach(); |
44 } | 45 } |
45 | 46 |
46 void CompactNavigationBar::Init() { | 47 void CompactNavigationBar::Init() { |
47 DCHECK(!initialized_); | 48 DCHECK(!initialized_); |
48 initialized_ = true; | 49 initialized_ = true; |
49 | 50 |
50 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | 51 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); |
51 | 52 |
52 back_button_ = new views::ImageButton(this); | 53 back_button_ = new views::ImageButton(this); |
53 back_button_->SetImage(views::CustomButton::BS_NORMAL, | 54 back_button_->SetImage(views::CustomButton::BS_NORMAL, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 kInnerPadding * 2; | 94 kInnerPadding * 2; |
94 | 95 |
95 width++; | 96 width++; |
96 return gfx::Size(width, kPreferredHeight); | 97 return gfx::Size(width, kPreferredHeight); |
97 } | 98 } |
98 | 99 |
99 void CompactNavigationBar::Layout() { | 100 void CompactNavigationBar::Layout() { |
100 if (!initialized_) | 101 if (!initialized_) |
101 return; | 102 return; |
102 | 103 |
103 int curx = 0; | 104 // We hide navigation buttons when the entry has focus. Navigation |
| 105 // buttons' visibility is controlled in OnKillFocus/OnSetFocus methods. |
| 106 if (!back_button_->IsVisible()) { |
| 107 // Fill the view with the entry view while it has focus. |
| 108 location_entry_view_->SetBounds(kURLPadding, 0, |
| 109 width() - kHorizPadding, height()); |
| 110 } else { |
| 111 // Layout forward/back buttons after entry views as follows: |
| 112 // [Entry View] [Back]|[Forward] |
| 113 int curx = 0; |
| 114 // URL bar. |
| 115 location_entry_view_->SetBounds(curx + kURLPadding, 0, |
| 116 kURLWidth + kURLPadding * 2, height()); |
| 117 curx += kURLWidth + kHorizPadding + kURLPadding * 2; |
104 | 118 |
105 // "Back | Forward" section. | 119 // "Back | Forward" section. |
106 gfx::Size button_size = back_button_->GetPreferredSize(); | 120 gfx::Size button_size = back_button_->GetPreferredSize(); |
107 button_size.set_width(button_size.width() + kInnerPadding * 2); | 121 button_size.set_width(button_size.width() + kInnerPadding * 2); |
108 back_button_->SetBounds(curx, 0, button_size.width(), height()); | 122 back_button_->SetBounds(curx, 0, button_size.width(), height()); |
109 curx += button_size.width() + kHorizPadding; | 123 curx += button_size.width() + kHorizPadding; |
110 | 124 |
111 button_size = bf_separator_->GetPreferredSize(); | 125 button_size = bf_separator_->GetPreferredSize(); |
112 bf_separator_->SetBounds(curx, 0, button_size.width(), height()); | 126 bf_separator_->SetBounds(curx, 0, button_size.width(), height()); |
113 curx += button_size.width() + kHorizPadding; | 127 curx += button_size.width() + kHorizPadding; |
114 | 128 |
115 button_size = forward_button_->GetPreferredSize(); | 129 button_size = forward_button_->GetPreferredSize(); |
116 button_size.set_width(button_size.width() + kInnerPadding * 2); | 130 button_size.set_width(button_size.width() + kInnerPadding * 2); |
117 forward_button_->SetBounds(curx, 0, button_size.width(), height()); | 131 forward_button_->SetBounds(curx, 0, button_size.width(), height()); |
118 curx += button_size.width() + kHorizPadding; | 132 curx += button_size.width() + kHorizPadding; |
119 | 133 } |
120 // URL bar. | |
121 location_entry_view_->SetBounds(curx + kURLPadding, 0, | |
122 kURLWidth + kURLPadding * 2, height()); | |
123 curx += kURLWidth + kHorizPadding + kURLPadding * 2; | |
124 } | 134 } |
125 | 135 |
126 void CompactNavigationBar::Paint(gfx::Canvas* canvas) { | 136 void CompactNavigationBar::Paint(gfx::Canvas* canvas) { |
127 ThemeProvider* theme = browser_->profile()->GetThemeProvider(); | 137 ThemeProvider* theme = browser_->profile()->GetThemeProvider(); |
128 | 138 |
129 // Fill the background. | 139 // Fill the background. |
130 int image_name; | 140 int image_name; |
131 if (browser_->window()->IsActive()) { | 141 if (browser_->window()->IsActive()) { |
132 image_name = browser_->profile()->IsOffTheRecord() ? | 142 image_name = browser_->profile()->IsOffTheRecord() ? |
133 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; | 143 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 AddTabWithURL(url, transition); | 183 AddTabWithURL(url, transition); |
174 } | 184 } |
175 | 185 |
176 void CompactNavigationBar::OnChanged() { | 186 void CompactNavigationBar::OnChanged() { |
177 // Other one does "DoLayout" here. | 187 // Other one does "DoLayout" here. |
178 } | 188 } |
179 | 189 |
180 void CompactNavigationBar::OnInputInProgress(bool in_progress) { | 190 void CompactNavigationBar::OnInputInProgress(bool in_progress) { |
181 } | 191 } |
182 | 192 |
| 193 void CompactNavigationBar::OnKillFocus() { |
| 194 back_button_->SetVisible(true); |
| 195 bf_separator_->SetVisible(true); |
| 196 forward_button_->SetVisible(true); |
| 197 Layout(); |
| 198 SchedulePaint(); |
| 199 } |
| 200 |
183 void CompactNavigationBar::OnSetFocus() { | 201 void CompactNavigationBar::OnSetFocus() { |
| 202 back_button_->SetVisible(false); |
| 203 bf_separator_->SetVisible(false); |
| 204 forward_button_->SetVisible(false); |
| 205 Layout(); |
| 206 SchedulePaint(); |
184 } | 207 } |
185 | 208 |
186 SkBitmap CompactNavigationBar::GetFavIcon() const { | 209 SkBitmap CompactNavigationBar::GetFavIcon() const { |
187 return SkBitmap(); | 210 return SkBitmap(); |
188 } | 211 } |
189 | 212 |
190 std::wstring CompactNavigationBar::GetTitle() const { | 213 std::wstring CompactNavigationBar::GetTitle() const { |
191 return std::wstring(); | 214 return std::wstring(); |
192 } | 215 } |
193 | 216 |
(...skipping 17 matching lines...) Expand all Loading... |
211 browser_->GetSelectedTabContents()->controller().LoadURL( | 234 browser_->GetSelectedTabContents()->controller().LoadURL( |
212 url, GURL(), transition); | 235 url, GURL(), transition); |
213 break; | 236 break; |
214 } | 237 } |
215 case StatusAreaView::OPEN_TABS_ON_RIGHT: { | 238 case StatusAreaView::OPEN_TABS_ON_RIGHT: { |
216 browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL); | 239 browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL); |
217 break; | 240 break; |
218 } | 241 } |
219 } | 242 } |
220 } | 243 } |
OLD | NEW |