| 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 "content/shell/shell.h" | 5 #include "content/shell/shell.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "ui/aura/desktop/desktop_screen.h" | 9 #include "ui/aura/desktop/desktop_screen.h" |
| 10 #include "ui/aura/display_manager.h" | 10 #include "ui/aura/display_manager.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ui/views/controls/textfield/textfield_controller.h" | 22 #include "ui/views/controls/textfield/textfield_controller.h" |
| 23 #include "ui/views/controls/webview/webview.h" | 23 #include "ui/views/controls/webview/webview.h" |
| 24 #include "ui/views/layout/fill_layout.h" | 24 #include "ui/views/layout/fill_layout.h" |
| 25 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
| 26 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| 27 #include "ui/views/test/desktop_test_views_delegate.h" | 27 #include "ui/views/test/desktop_test_views_delegate.h" |
| 28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
| 30 | 30 |
| 31 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 32 #include "ash/screen_ash.h" |
| 32 #include "chromeos/dbus/dbus_thread_manager.h" | 33 #include "chromeos/dbus/dbus_thread_manager.h" |
| 33 #include "content/shell/shell_stacking_client_ash.h" | 34 #include "content/shell/shell_stacking_client_ash.h" |
| 34 #else | 35 #else |
| 35 #include "ui/aura/desktop/desktop_stacking_client.h" | 36 #include "ui/aura/desktop/desktop_stacking_client.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 // ViewDelegate implementation for aura content shell | 39 // ViewDelegate implementation for aura content shell |
| 39 class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { | 40 class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { |
| 40 public: | 41 public: |
| 41 ShellViewsDelegateAura() : use_transparent_windows_(false) { | 42 ShellViewsDelegateAura() : use_transparent_windows_(false) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 layout->AddPaddingRow(0, 5); | 186 layout->AddPaddingRow(0, 5); |
| 186 | 187 |
| 187 // Add web contents view as the second row | 188 // Add web contents view as the second row |
| 188 { | 189 { |
| 189 layout->StartRow(1, 0); | 190 layout->StartRow(1, 0); |
| 190 layout->AddView(contents_view_); | 191 layout->AddView(contents_view_); |
| 191 } | 192 } |
| 192 | 193 |
| 193 layout->AddPaddingRow(0, 5); | 194 layout->AddPaddingRow(0, 5); |
| 194 } | 195 } |
| 195 // Overriden from TextfieldController | 196 // Overridden from TextfieldController |
| 196 virtual void ContentsChanged(Textfield* sender, | 197 virtual void ContentsChanged(Textfield* sender, |
| 197 const string16& new_contents) OVERRIDE { | 198 const string16& new_contents) OVERRIDE { |
| 198 } | 199 } |
| 199 virtual bool HandleKeyEvent(Textfield* sender, | 200 virtual bool HandleKeyEvent(Textfield* sender, |
| 200 const ui::KeyEvent& key_event) OVERRIDE { | 201 const ui::KeyEvent& key_event) OVERRIDE { |
| 201 if (sender == url_entry_ && key_event.key_code() == ui::VKEY_RETURN) { | 202 if (sender == url_entry_ && key_event.key_code() == ui::VKEY_RETURN) { |
| 202 std::string text = UTF16ToUTF8(url_entry_->text()); | 203 std::string text = UTF16ToUTF8(url_entry_->text()); |
| 203 GURL url(text); | 204 GURL url(text); |
| 204 if (!url.has_scheme()) { | 205 if (!url.has_scheme()) { |
| 205 url = GURL(std::string("http://") + std::string(text)); | 206 url = GURL(std::string("http://") + std::string(text)); |
| 206 url_entry_->SetText(ASCIIToUTF16(url.spec())); | 207 url_entry_->SetText(ASCIIToUTF16(url.spec())); |
| 207 } | 208 } |
| 208 shell_->LoadURL(url); | 209 shell_->LoadURL(url); |
| 209 return true; | 210 return true; |
| 210 } | 211 } |
| 211 return false; | 212 return false; |
| 212 } | 213 } |
| 213 | 214 |
| 214 // Overriden from ButtonListener | 215 // Overridden from ButtonListener |
| 215 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { | 216 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { |
| 216 if (sender == back_button_) | 217 if (sender == back_button_) |
| 217 shell_->GoBackOrForward(-1); | 218 shell_->GoBackOrForward(-1); |
| 218 else if (sender == forward_button_) | 219 else if (sender == forward_button_) |
| 219 shell_->GoBackOrForward(1); | 220 shell_->GoBackOrForward(1); |
| 220 else if (sender == refresh_button_) | 221 else if (sender == refresh_button_) |
| 221 shell_->Reload(); | 222 shell_->Reload(); |
| 222 else if (sender == stop_button_) | 223 else if (sender == stop_button_) |
| 223 shell_->Stop(); | 224 shell_->Stop(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 // Overriden from WidgetDelegateView | 227 // Overridden from WidgetDelegateView |
| 227 virtual bool CanResize() const OVERRIDE { return true; } | 228 virtual bool CanResize() const OVERRIDE { return true; } |
| 228 virtual bool CanMaximize() const OVERRIDE { return true; } | 229 virtual bool CanMaximize() const OVERRIDE { return true; } |
| 229 virtual string16 GetWindowTitle() const OVERRIDE { | 230 virtual string16 GetWindowTitle() const OVERRIDE { |
| 230 return title_; | 231 return title_; |
| 231 } | 232 } |
| 232 virtual void WindowClosing() OVERRIDE { | 233 virtual void WindowClosing() OVERRIDE { |
| 233 if (shell_) { | 234 if (shell_) { |
| 234 delete shell_; | 235 delete shell_; |
| 235 shell_ = NULL; | 236 shell_ = NULL; |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 virtual View* GetContentsView() OVERRIDE { return this; } | 239 virtual View* GetContentsView() OVERRIDE { return this; } |
| 239 | 240 |
| 240 // Overriden from View | 241 // Overridden from View |
| 241 virtual void ViewHierarchyChanged(bool is_add, | 242 virtual void ViewHierarchyChanged(bool is_add, |
| 242 View* parent, | 243 View* parent, |
| 243 View* child) OVERRIDE { | 244 View* child) OVERRIDE { |
| 244 if (is_add && child == this) { | 245 if (is_add && child == this) { |
| 245 InitShellWindow(); | 246 InitShellWindow(); |
| 246 } | 247 } |
| 247 } | 248 } |
| 248 | 249 |
| 249 private: | 250 private: |
| 250 // Hold a reference of Shell for deleting it when the window is closing | 251 // Hold a reference of Shell for deleting it when the window is closing |
| (...skipping 27 matching lines...) Expand all Loading... |
| 278 views::ViewsDelegate* Shell::views_delegate_ = NULL; | 279 views::ViewsDelegate* Shell::views_delegate_ = NULL; |
| 279 | 280 |
| 280 // static | 281 // static |
| 281 void Shell::PlatformInitialize() { | 282 void Shell::PlatformInitialize() { |
| 282 #if defined(OS_CHROMEOS) | 283 #if defined(OS_CHROMEOS) |
| 283 chromeos::DBusThreadManager::Initialize(); | 284 chromeos::DBusThreadManager::Initialize(); |
| 284 #endif | 285 #endif |
| 285 aura::Env::GetInstance()->SetDisplayManager(new aura::SingleDisplayManager); | 286 aura::Env::GetInstance()->SetDisplayManager(new aura::SingleDisplayManager); |
| 286 #if defined(OS_CHROMEOS) | 287 #if defined(OS_CHROMEOS) |
| 287 stacking_client_ = new content::ShellStackingClientAsh(); | 288 stacking_client_ = new content::ShellStackingClientAsh(); |
| 289 gfx::Screen::SetScreenInstance( |
| 290 gfx::SCREEN_TYPE_NATIVE, new ash::ScreenAsh); |
| 288 #else | 291 #else |
| 289 stacking_client_ = new aura::DesktopStackingClient(); | 292 stacking_client_ = new aura::DesktopStackingClient(); |
| 290 #endif | |
| 291 gfx::Screen::SetScreenInstance( | 293 gfx::Screen::SetScreenInstance( |
| 292 gfx::SCREEN_TYPE_NATIVE, aura::CreateDesktopScreen()); | 294 gfx::SCREEN_TYPE_NATIVE, aura::CreateDesktopScreen()); |
| 295 #endif |
| 293 views_delegate_ = new ShellViewsDelegateAura(); | 296 views_delegate_ = new ShellViewsDelegateAura(); |
| 294 } | 297 } |
| 295 | 298 |
| 296 void Shell::PlatformExit() { | 299 void Shell::PlatformExit() { |
| 297 if (stacking_client_) | 300 if (stacking_client_) |
| 298 delete stacking_client_; | 301 delete stacking_client_; |
| 299 if (views_delegate_) | 302 if (views_delegate_) |
| 300 delete views_delegate_; | 303 delete views_delegate_; |
| 301 #if defined(OS_CHROMEOS) | 304 #if defined(OS_CHROMEOS) |
| 302 chromeos::DBusThreadManager::Shutdown(); | 305 chromeos::DBusThreadManager::Shutdown(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 356 } |
| 354 | 357 |
| 355 void Shell::PlatformSetTitle(const string16& title) { | 358 void Shell::PlatformSetTitle(const string16& title) { |
| 356 ShellWindowDelegateView* delegate_view = | 359 ShellWindowDelegateView* delegate_view = |
| 357 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 360 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
| 358 delegate_view->SetWindowTitle(title); | 361 delegate_view->SetWindowTitle(title); |
| 359 window_widget_->UpdateWindowTitle(); | 362 window_widget_->UpdateWindowTitle(); |
| 360 } | 363 } |
| 361 | 364 |
| 362 } // namespace content | 365 } // namespace content |
| OLD | NEW |