OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell.h" | 5 #include "content/shell/browser/shell.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_view.h" | 10 #include "content/public/browser/web_contents_view.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 layout->AddPaddingRow(0, 5); | 203 layout->AddPaddingRow(0, 5); |
204 | 204 |
205 // Add web contents view as the second row | 205 // Add web contents view as the second row |
206 { | 206 { |
207 layout->StartRow(1, 0); | 207 layout->StartRow(1, 0); |
208 layout->AddView(contents_view_); | 208 layout->AddView(contents_view_); |
209 } | 209 } |
210 | 210 |
211 layout->AddPaddingRow(0, 5); | 211 layout->AddPaddingRow(0, 5); |
| 212 |
| 213 InitAccelerators(); |
| 214 } |
| 215 void InitAccelerators() { |
| 216 static const ui::KeyboardCode keys[] = { ui::VKEY_F5, |
| 217 ui::VKEY_BROWSER_BACK, |
| 218 ui::VKEY_BROWSER_FORWARD }; |
| 219 for (size_t i = 0; i < arraysize(keys); ++i) { |
| 220 GetFocusManager()->RegisterAccelerator( |
| 221 ui::Accelerator(keys[i], ui::EF_NONE), |
| 222 ui::AcceleratorManager::kNormalPriority, |
| 223 this); |
| 224 } |
212 } | 225 } |
213 // Overridden from TextfieldController | 226 // Overridden from TextfieldController |
214 virtual void ContentsChanged(views::Textfield* sender, | 227 virtual void ContentsChanged(views::Textfield* sender, |
215 const base::string16& new_contents) OVERRIDE { | 228 const base::string16& new_contents) OVERRIDE { |
216 } | 229 } |
217 virtual bool HandleKeyEvent(views::Textfield* sender, | 230 virtual bool HandleKeyEvent(views::Textfield* sender, |
218 const ui::KeyEvent& key_event) OVERRIDE { | 231 const ui::KeyEvent& key_event) OVERRIDE { |
219 if (sender == url_entry_ && key_event.key_code() == ui::VKEY_RETURN) { | 232 if (sender == url_entry_ && key_event.key_code() == ui::VKEY_RETURN) { |
220 std::string text = base::UTF16ToUTF8(url_entry_->text()); | 233 std::string text = base::UTF16ToUTF8(url_entry_->text()); |
221 GURL url(text); | 234 GURL url(text); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 virtual View* GetContentsView() OVERRIDE { return this; } | 270 virtual View* GetContentsView() OVERRIDE { return this; } |
258 | 271 |
259 // Overridden from View | 272 // Overridden from View |
260 virtual void ViewHierarchyChanged( | 273 virtual void ViewHierarchyChanged( |
261 const ViewHierarchyChangedDetails& details) OVERRIDE { | 274 const ViewHierarchyChangedDetails& details) OVERRIDE { |
262 if (details.is_add && details.child == this) { | 275 if (details.is_add && details.child == this) { |
263 InitShellWindow(); | 276 InitShellWindow(); |
264 } | 277 } |
265 } | 278 } |
266 | 279 |
| 280 // Overridden from AcceleratorTarget: |
| 281 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { |
| 282 switch (accelerator.key_code()) { |
| 283 case ui::VKEY_F5: |
| 284 shell_->Reload(); |
| 285 return true; |
| 286 case ui::VKEY_BROWSER_BACK: |
| 287 shell_->GoBackOrForward(-1); |
| 288 return true; |
| 289 case ui::VKEY_BROWSER_FORWARD: |
| 290 shell_->GoBackOrForward(1); |
| 291 return true; |
| 292 default: |
| 293 return views::WidgetDelegateView::AcceleratorPressed(accelerator); |
| 294 } |
| 295 } |
| 296 |
267 private: | 297 private: |
268 // Hold a reference of Shell for deleting it when the window is closing | 298 // Hold a reference of Shell for deleting it when the window is closing |
269 Shell* shell_; | 299 Shell* shell_; |
270 | 300 |
271 // Window title | 301 // Window title |
272 base::string16 title_; | 302 base::string16 title_; |
273 | 303 |
274 // Toolbar view contains forward/backward/reload button and URL entry | 304 // Toolbar view contains forward/backward/reload button and URL entry |
275 View* toolbar_view_; | 305 View* toolbar_view_; |
276 views::LabelButton* back_button_; | 306 views::LabelButton* back_button_; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 415 } |
386 | 416 |
387 void Shell::PlatformSetTitle(const base::string16& title) { | 417 void Shell::PlatformSetTitle(const base::string16& title) { |
388 ShellWindowDelegateView* delegate_view = | 418 ShellWindowDelegateView* delegate_view = |
389 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 419 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
390 delegate_view->SetWindowTitle(title); | 420 delegate_view->SetWindowTitle(title); |
391 window_widget_->UpdateWindowTitle(); | 421 window_widget_->UpdateWindowTitle(); |
392 } | 422 } |
393 | 423 |
394 } // namespace content | 424 } // namespace content |
OLD | NEW |