| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/apps/native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/app_window.h" | |
| 8 #include "apps/ui/views/app_window_frame_view.h" | 7 #include "apps/ui/views/app_window_frame_view.h" |
| 9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | |
| 11 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/app_mode/app_mode_utils.h" | 10 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 13 #include "chrome/browser/chrome_page_zoom.h" | 11 #include "chrome/browser/chrome_page_zoom.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | |
| 15 #include "chrome/browser/favicon/favicon_tab_helper.h" | 12 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" | |
| 18 #include "chrome/browser/ui/host_desktop.h" | |
| 19 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | |
| 20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 14 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 21 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 15 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
| 22 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 24 #include "content/public/browser/browser_thread.h" | |
| 25 #include "content/public/browser/render_view_host.h" | |
| 26 #include "content/public/browser/render_widget_host_view.h" | |
| 27 #include "content/public/browser/web_contents.h" | |
| 28 #include "content/public/browser/web_contents_view.h" | |
| 29 #include "extensions/common/draggable_region.h" | |
| 30 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 31 #include "ui/base/hit_test.h" | |
| 32 #include "ui/base/models/simple_menu_model.h" | 19 #include "ui/base/models/simple_menu_model.h" |
| 33 #include "ui/views/controls/menu/menu_runner.h" | 20 #include "ui/views/controls/menu/menu_runner.h" |
| 34 #include "ui/views/controls/webview/webview.h" | 21 #include "ui/views/controls/webview/webview.h" |
| 35 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 36 #include "ui/views/window/non_client_view.h" | |
| 37 | 23 |
| 38 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
| 39 #include "chrome/browser/shell_integration_linux.h" | 25 #include "chrome/browser/shell_integration_linux.h" |
| 40 #endif | 26 #endif |
| 41 | 27 |
| 42 #if defined(USE_ASH) | 28 #if defined(USE_ASH) |
| 43 #include "ash/ash_constants.h" | 29 #include "ash/ash_constants.h" |
| 44 #include "ash/ash_switches.h" | 30 #include "ash/ash_switches.h" |
| 45 #include "ash/screen_util.h" | 31 #include "ash/screen_util.h" |
| 46 #include "ash/shell.h" | 32 #include "ash/shell.h" |
| 47 #include "ash/wm/custom_frame_view_ash.h" | 33 #include "ash/wm/custom_frame_view_ash.h" |
| 48 #include "ash/wm/immersive_fullscreen_controller.h" | 34 #include "ash/wm/immersive_fullscreen_controller.h" |
| 49 #include "ash/wm/panels/panel_frame_view.h" | 35 #include "ash/wm/panels/panel_frame_view.h" |
| 50 #include "ash/wm/window_state.h" | 36 #include "ash/wm/window_state.h" |
| 51 #include "ash/wm/window_state_delegate.h" | 37 #include "ash/wm/window_state_delegate.h" |
| 52 #include "ash/wm/window_state_observer.h" | 38 #include "ash/wm/window_state_observer.h" |
| 53 #include "chrome/browser/ui/ash/ash_util.h" | 39 #include "chrome/browser/ui/ash/ash_util.h" |
| 40 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
| 54 #include "ui/aura/client/aura_constants.h" | 41 #include "ui/aura/client/aura_constants.h" |
| 55 #include "ui/aura/client/window_tree_client.h" | 42 #include "ui/aura/client/window_tree_client.h" |
| 56 #include "ui/aura/window.h" | 43 #include "ui/aura/window.h" |
| 57 #include "ui/aura/window_observer.h" | 44 #include "ui/aura/window_observer.h" |
| 58 #endif | 45 #endif |
| 59 | 46 |
| 60 #if defined(USE_AURA) | |
| 61 #include "ui/aura/window.h" | |
| 62 #endif | |
| 63 | |
| 64 using apps::AppWindow; | 47 using apps::AppWindow; |
| 65 | 48 |
| 66 namespace { | 49 namespace { |
| 67 | 50 |
| 68 const int kMinPanelWidth = 100; | 51 const int kMinPanelWidth = 100; |
| 69 const int kMinPanelHeight = 100; | 52 const int kMinPanelHeight = 100; |
| 70 const int kDefaultPanelWidth = 200; | 53 const int kDefaultPanelWidth = 200; |
| 71 const int kDefaultPanelHeight = 300; | 54 const int kDefaultPanelHeight = 300; |
| 72 const int kResizeInsideBoundsSize = 5; | 55 const int kResizeInsideBoundsSize = 5; |
| 73 const int kResizeAreaCornerSize = 16; | 56 const int kResizeAreaCornerSize = 16; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // Not owned. | 175 // Not owned. |
| 193 AppWindow* app_window_; | 176 AppWindow* app_window_; |
| 194 ash::wm::WindowState* window_state_; | 177 ash::wm::WindowState* window_state_; |
| 195 | 178 |
| 196 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | 179 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); |
| 197 }; | 180 }; |
| 198 #endif // USE_ASH | 181 #endif // USE_ASH |
| 199 | 182 |
| 200 } // namespace | 183 } // namespace |
| 201 | 184 |
| 202 NativeAppWindowViews::NativeAppWindowViews() | 185 ChromeNativeAppWindowViews::ChromeNativeAppWindowViews() |
| 203 : web_view_(NULL), | 186 : is_fullscreen_(false) {} |
| 204 window_(NULL), | |
| 205 is_fullscreen_(false), | |
| 206 weak_ptr_factory_(this) { | |
| 207 } | |
| 208 | 187 |
| 209 void NativeAppWindowViews::Init(apps::AppWindow* app_window, | 188 ChromeNativeAppWindowViews::~ChromeNativeAppWindowViews() {} |
| 210 const AppWindow::CreateParams& create_params) { | |
| 211 app_window_ = app_window; | |
| 212 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | |
| 213 transparent_background_ = create_params.transparent_background; | |
| 214 resizable_ = create_params.resizable; | |
| 215 Observe(web_contents()); | |
| 216 | 189 |
| 217 window_ = new views::Widget; | 190 void ChromeNativeAppWindowViews::OnBeforeWidgetInit( |
| 218 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || | |
| 219 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { | |
| 220 InitializePanelWindow(create_params); | |
| 221 } else { | |
| 222 InitializeDefaultWindow(create_params); | |
| 223 } | |
| 224 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | |
| 225 Profile::FromBrowserContext(browser_context()), | |
| 226 window_->GetFocusManager(), | |
| 227 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | |
| 228 app_window_)); | |
| 229 | |
| 230 OnViewWasResized(); | |
| 231 window_->AddObserver(this); | |
| 232 } | |
| 233 | |
| 234 NativeAppWindowViews::~NativeAppWindowViews() { | |
| 235 web_view_->SetWebContents(NULL); | |
| 236 } | |
| 237 | |
| 238 void NativeAppWindowViews::OnBeforeWidgetInit( | |
| 239 views::Widget::InitParams* init_params, | 191 views::Widget::InitParams* init_params, |
| 240 views::Widget* widget) {} | 192 views::Widget* widget) {} |
| 241 | 193 |
| 242 void NativeAppWindowViews::InitializeDefaultWindow( | 194 void ChromeNativeAppWindowViews::InitializeDefaultWindow( |
| 243 const AppWindow::CreateParams& create_params) { | 195 const AppWindow::CreateParams& create_params) { |
| 244 std::string app_name = | 196 std::string app_name = |
| 245 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); | 197 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); |
| 246 | 198 |
| 247 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 199 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 248 init_params.delegate = this; | 200 init_params.delegate = this; |
| 249 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); | 201 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); |
| 250 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 202 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 251 // On Linux, remove the standard frame. Instead, we will use CustomFrameView | 203 // On Linux, remove the standard frame. Instead, we will use CustomFrameView |
| 252 // to draw a native-like frame. | 204 // to draw a native-like frame. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 268 | 220 |
| 269 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 221 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 270 // Set up a custom WM_CLASS for app windows. This allows task switchers in | 222 // Set up a custom WM_CLASS for app windows. This allows task switchers in |
| 271 // X11 environments to distinguish them from main browser windows. | 223 // X11 environments to distinguish them from main browser windows. |
| 272 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); | 224 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); |
| 273 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); | 225 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); |
| 274 const char kX11WindowRoleApp[] = "app"; | 226 const char kX11WindowRoleApp[] = "app"; |
| 275 init_params.wm_role_name = std::string(kX11WindowRoleApp); | 227 init_params.wm_role_name = std::string(kX11WindowRoleApp); |
| 276 #endif | 228 #endif |
| 277 | 229 |
| 278 OnBeforeWidgetInit(&init_params, window_); | 230 OnBeforeWidgetInit(&init_params, window()); |
| 279 window_->Init(init_params); | 231 window()->Init(init_params); |
| 280 | 232 |
| 281 gfx::Rect adjusted_bounds = window_bounds; | 233 gfx::Rect adjusted_bounds = window_bounds; |
| 282 adjusted_bounds.Inset(-GetFrameInsets()); | 234 adjusted_bounds.Inset(-GetFrameInsets()); |
| 283 // Center window if no position was specified. | 235 // Center window if no position was specified. |
| 284 if (!position_specified) | 236 if (!position_specified) |
| 285 window_->CenterWindow(adjusted_bounds.size()); | 237 window()->CenterWindow(adjusted_bounds.size()); |
| 286 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) | 238 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) |
| 287 window_->SetBounds(adjusted_bounds); | 239 window()->SetBounds(adjusted_bounds); |
| 288 | 240 |
| 289 // Register accelarators supported by app windows. | 241 // Register accelarators supported by app windows. |
| 290 // TODO(jeremya/stevenjb): should these be registered for panels too? | 242 // TODO(jeremya/stevenjb): should these be registered for panels too? |
| 291 views::FocusManager* focus_manager = GetFocusManager(); | 243 views::FocusManager* focus_manager = GetFocusManager(); |
| 292 const std::map<ui::Accelerator, int>& accelerator_table = | 244 const std::map<ui::Accelerator, int>& accelerator_table = |
| 293 GetAcceleratorTable(); | 245 GetAcceleratorTable(); |
| 294 const bool is_kiosk_app_mode = chrome::IsRunningInForcedAppMode(); | 246 const bool is_kiosk_app_mode = chrome::IsRunningInForcedAppMode(); |
| 295 | 247 |
| 296 // Ensures that kiosk mode accelerators are enabled when in kiosk mode (to be | 248 // Ensures that kiosk mode accelerators are enabled when in kiosk mode (to be |
| 297 // future proof). This is needed because GetAcceleratorTable() uses a static | 249 // future proof). This is needed because GetAcceleratorTable() uses a static |
| 298 // to store data and only checks kiosk mode once. If a platform app is | 250 // to store data and only checks kiosk mode once. If a platform app is |
| 299 // launched before kiosk mode starts, the kiosk accelerators will not be | 251 // launched before kiosk mode starts, the kiosk accelerators will not be |
| 300 // registered. This DCHECK catches the case. | 252 // registered. This DCHECK catches the case. |
| 301 DCHECK(!is_kiosk_app_mode || | 253 DCHECK(!is_kiosk_app_mode || |
| 302 accelerator_table.size() == | 254 accelerator_table.size() == |
| 303 arraysize(kAppWindowAcceleratorMap) + | 255 arraysize(kAppWindowAcceleratorMap) + |
| 304 arraysize(kAppWindowKioskAppModeAcceleratorMap)); | 256 arraysize(kAppWindowKioskAppModeAcceleratorMap)); |
| 305 | 257 |
| 306 for (std::map<ui::Accelerator, int>::const_iterator iter = | 258 for (std::map<ui::Accelerator, int>::const_iterator iter = |
| 307 accelerator_table.begin(); | 259 accelerator_table.begin(); |
| 308 iter != accelerator_table.end(); ++iter) { | 260 iter != accelerator_table.end(); ++iter) { |
| 309 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) | 261 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) |
| 310 continue; | 262 continue; |
| 311 | 263 |
| 312 focus_manager->RegisterAccelerator( | 264 focus_manager->RegisterAccelerator( |
| 313 iter->first, ui::AcceleratorManager::kNormalPriority, this); | 265 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
| 314 } | 266 } |
| 315 } | 267 } |
| 316 | 268 |
| 317 void NativeAppWindowViews::InitializePanelWindow( | 269 void ChromeNativeAppWindowViews::InitializePanelWindow( |
| 318 const AppWindow::CreateParams& create_params) { | 270 const AppWindow::CreateParams& create_params) { |
| 319 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 271 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
| 320 params.delegate = this; | 272 params.delegate = this; |
| 321 | 273 |
| 322 preferred_size_ = gfx::Size(create_params.bounds.width(), | 274 preferred_size_ = gfx::Size(create_params.bounds.width(), |
| 323 create_params.bounds.height()); | 275 create_params.bounds.height()); |
| 324 if (preferred_size_.width() == 0) | 276 if (preferred_size_.width() == 0) |
| 325 preferred_size_.set_width(kDefaultPanelWidth); | 277 preferred_size_.set_width(kDefaultPanelWidth); |
| 326 else if (preferred_size_.width() < kMinPanelWidth) | 278 else if (preferred_size_.width() < kMinPanelWidth) |
| 327 preferred_size_.set_width(kMinPanelWidth); | 279 preferred_size_.set_width(kMinPanelWidth); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 338 target, gfx::Rect(preferred_size_)); | 290 target, gfx::Rect(preferred_size_)); |
| 339 } else { | 291 } else { |
| 340 params.bounds = gfx::Rect(preferred_size_); | 292 params.bounds = gfx::Rect(preferred_size_); |
| 341 } | 293 } |
| 342 #else | 294 #else |
| 343 params.bounds = gfx::Rect(preferred_size_); | 295 params.bounds = gfx::Rect(preferred_size_); |
| 344 #endif | 296 #endif |
| 345 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 297 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
| 346 // could plumb context through to here in some cases. | 298 // could plumb context through to here in some cases. |
| 347 params.top_level = true; | 299 params.top_level = true; |
| 348 window_->Init(params); | 300 window()->Init(params); |
| 349 window_->set_focus_on_creation(create_params.focused); | 301 window()->set_focus_on_creation(create_params.focused); |
| 350 | 302 |
| 351 #if defined(USE_ASH) | 303 #if defined(USE_ASH) |
| 352 if (create_params.state == ui::SHOW_STATE_DETACHED) { | 304 if (create_params.state == ui::SHOW_STATE_DETACHED) { |
| 353 gfx::Rect window_bounds(create_params.bounds.x(), | 305 gfx::Rect window_bounds(create_params.bounds.x(), |
| 354 create_params.bounds.y(), | 306 create_params.bounds.y(), |
| 355 preferred_size_.width(), | 307 preferred_size_.width(), |
| 356 preferred_size_.height()); | 308 preferred_size_.height()); |
| 357 aura::Window* native_window = GetNativeWindow(); | 309 aura::Window* native_window = GetNativeWindow(); |
| 358 ash::wm::GetWindowState(native_window)->set_panel_attached(false); | 310 ash::wm::GetWindowState(native_window)->set_panel_attached(false); |
| 359 aura::client::ParentWindowWithContext(native_window, | 311 aura::client::ParentWindowWithContext(native_window, |
| 360 native_window->GetRootWindow(), | 312 native_window->GetRootWindow(), |
| 361 native_window->GetBoundsInScreen()); | 313 native_window->GetBoundsInScreen()); |
| 362 window_->SetBounds(window_bounds); | 314 window()->SetBounds(window_bounds); |
| 363 } | 315 } |
| 364 #else | 316 #else |
| 365 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | 317 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
| 366 // platforms. | 318 // platforms. |
| 367 #endif | 319 #endif |
| 368 } | 320 } |
| 369 | 321 |
| 370 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { | 322 // ui::BaseWindow overrides: |
| 371 if (frameless_) | |
| 372 return true; | |
| 373 | 323 |
| 374 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 324 ui::WindowShowState ChromeNativeAppWindowViews::GetRestoredState() const { |
| 375 // Linux always uses native style frames. | |
| 376 return false; | |
| 377 #endif | |
| 378 | |
| 379 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 380 switches::kAppsUseNativeFrame); | |
| 381 } | |
| 382 | |
| 383 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { | |
| 384 // By default the user can resize the window from slightly inside the bounds. | |
| 385 int resize_inside_bounds_size = kResizeInsideBoundsSize; | |
| 386 int resize_outside_bounds_size = 0; | |
| 387 int resize_outside_scale_for_touch = 1; | |
| 388 int resize_area_corner_size = kResizeAreaCornerSize; | |
| 389 #if defined(USE_ASH) | |
| 390 // For Aura windows on the Ash desktop the sizes are different and the user | |
| 391 // can resize the window from slightly outside the bounds as well. | |
| 392 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { | |
| 393 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | |
| 394 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; | |
| 395 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; | |
| 396 resize_area_corner_size = ash::kResizeAreaCornerSize; | |
| 397 } | |
| 398 #endif | |
| 399 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); | |
| 400 frame_view->Init(window_, | |
| 401 resize_inside_bounds_size, | |
| 402 resize_outside_bounds_size, | |
| 403 resize_outside_scale_for_touch, | |
| 404 resize_area_corner_size); | |
| 405 return frame_view; | |
| 406 } | |
| 407 | |
| 408 // ui::BaseWindow implementation. | |
| 409 | |
| 410 bool NativeAppWindowViews::IsActive() const { | |
| 411 return window_->IsActive(); | |
| 412 } | |
| 413 | |
| 414 bool NativeAppWindowViews::IsMaximized() const { | |
| 415 return window_->IsMaximized(); | |
| 416 } | |
| 417 | |
| 418 bool NativeAppWindowViews::IsMinimized() const { | |
| 419 return window_->IsMinimized(); | |
| 420 } | |
| 421 | |
| 422 bool NativeAppWindowViews::IsFullscreen() const { | |
| 423 return window_->IsFullscreen(); | |
| 424 } | |
| 425 | |
| 426 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { | |
| 427 return window_->GetNativeWindow(); | |
| 428 } | |
| 429 | |
| 430 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { | |
| 431 return window_->GetRestoredBounds(); | |
| 432 } | |
| 433 | |
| 434 ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { | |
| 435 if (IsMaximized()) | 325 if (IsMaximized()) |
| 436 return ui::SHOW_STATE_MAXIMIZED; | 326 return ui::SHOW_STATE_MAXIMIZED; |
| 437 if (IsFullscreen()) { | 327 if (IsFullscreen()) { |
| 438 #if defined(USE_ASH) | 328 #if defined(USE_ASH) |
| 439 if (immersive_fullscreen_controller_.get() && | 329 if (immersive_fullscreen_controller_.get() && |
| 440 immersive_fullscreen_controller_->IsEnabled()) { | 330 immersive_fullscreen_controller_->IsEnabled()) { |
| 441 // Restore windows which were previously in immersive fullscreen to | 331 // Restore windows which were previously in immersive fullscreen to |
| 442 // maximized. Restoring the window to a different fullscreen type | 332 // maximized. Restoring the window to a different fullscreen type |
| 443 // makes for a bad experience. | 333 // makes for a bad experience. |
| 444 return ui::SHOW_STATE_MAXIMIZED; | 334 return ui::SHOW_STATE_MAXIMIZED; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 463 case ui::SHOW_STATE_DEFAULT: | 353 case ui::SHOW_STATE_DEFAULT: |
| 464 case ui::SHOW_STATE_MINIMIZED: | 354 case ui::SHOW_STATE_MINIMIZED: |
| 465 case ui::SHOW_STATE_INACTIVE: | 355 case ui::SHOW_STATE_INACTIVE: |
| 466 case ui::SHOW_STATE_END: | 356 case ui::SHOW_STATE_END: |
| 467 return ui::SHOW_STATE_NORMAL; | 357 return ui::SHOW_STATE_NORMAL; |
| 468 } | 358 } |
| 469 #endif | 359 #endif |
| 470 return ui::SHOW_STATE_NORMAL; | 360 return ui::SHOW_STATE_NORMAL; |
| 471 } | 361 } |
| 472 | 362 |
| 473 gfx::Rect NativeAppWindowViews::GetBounds() const { | 363 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { |
| 474 return window_->GetWindowBoundsInScreen(); | 364 if (app_window()->window_type_is_panel()) { |
| 475 } | |
| 476 | |
| 477 void NativeAppWindowViews::Show() { | |
| 478 if (window_->IsVisible()) { | |
| 479 window_->Activate(); | |
| 480 return; | |
| 481 } | |
| 482 | |
| 483 window_->Show(); | |
| 484 } | |
| 485 | |
| 486 void NativeAppWindowViews::ShowInactive() { | |
| 487 if (window_->IsVisible()) | |
| 488 return; | |
| 489 window_->ShowInactive(); | |
| 490 } | |
| 491 | |
| 492 void NativeAppWindowViews::Hide() { | |
| 493 window_->Hide(); | |
| 494 } | |
| 495 | |
| 496 void NativeAppWindowViews::Close() { | |
| 497 window_->Close(); | |
| 498 } | |
| 499 | |
| 500 void NativeAppWindowViews::Activate() { | |
| 501 window_->Activate(); | |
| 502 } | |
| 503 | |
| 504 void NativeAppWindowViews::Deactivate() { | |
| 505 window_->Deactivate(); | |
| 506 } | |
| 507 | |
| 508 void NativeAppWindowViews::Maximize() { | |
| 509 window_->Maximize(); | |
| 510 } | |
| 511 | |
| 512 void NativeAppWindowViews::Minimize() { | |
| 513 window_->Minimize(); | |
| 514 } | |
| 515 | |
| 516 void NativeAppWindowViews::Restore() { | |
| 517 window_->Restore(); | |
| 518 } | |
| 519 | |
| 520 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { | |
| 521 window_->SetBounds(bounds); | |
| 522 } | |
| 523 | |
| 524 void NativeAppWindowViews::FlashFrame(bool flash) { | |
| 525 window_->FlashFrame(flash); | |
| 526 } | |
| 527 | |
| 528 bool NativeAppWindowViews::IsAlwaysOnTop() const { | |
| 529 if (app_window_->window_type_is_panel()) { | |
| 530 #if defined(USE_ASH) | 365 #if defined(USE_ASH) |
| 531 return ash::wm::GetWindowState(window_->GetNativeWindow())-> | 366 return ash::wm::GetWindowState(window()->GetNativeWindow())-> |
| 532 panel_attached(); | 367 panel_attached(); |
| 533 #else | 368 #else |
| 534 return true; | 369 return true; |
| 535 #endif | 370 #endif |
| 536 } else { | 371 } else { |
| 537 return window_->IsAlwaysOnTop(); | 372 return window()->IsAlwaysOnTop(); |
| 538 } | 373 } |
| 539 } | 374 } |
| 540 | 375 |
| 541 void NativeAppWindowViews::SetAlwaysOnTop(bool always_on_top) { | 376 // views::ContextMenuController overrides: |
| 542 window_->SetAlwaysOnTop(always_on_top); | |
| 543 } | |
| 544 | 377 |
| 545 void NativeAppWindowViews::ShowContextMenuForView( | 378 void ChromeNativeAppWindowViews::ShowContextMenuForView( |
| 546 views::View* source, | 379 views::View* source, |
| 547 const gfx::Point& p, | 380 const gfx::Point& p, |
| 548 ui::MenuSourceType source_type) { | 381 ui::MenuSourceType source_type) { |
| 549 #if defined(USE_ASH) & defined(OS_CHROMEOS) | 382 #if defined(USE_ASH) && defined(OS_CHROMEOS) |
| 550 scoped_ptr<ui::MenuModel> model = | 383 scoped_ptr<ui::MenuModel> model = |
| 551 CreateMultiUserContextMenu(app_window_->GetNativeWindow()); | 384 CreateMultiUserContextMenu(app_window_->GetNativeWindow()); |
| 552 if (!model.get()) | 385 if (!model.get()) |
| 553 return; | 386 return; |
| 554 | 387 |
| 555 // Only show context menu if point is in caption. | 388 // Only show context menu if point is in caption. |
| 556 gfx::Point point_in_view_coords(p); | 389 gfx::Point point_in_view_coords(p); |
| 557 views::View::ConvertPointFromScreen(window_->non_client_view(), | 390 views::View::ConvertPointFromScreen(window_->non_client_view(), |
| 558 &point_in_view_coords); | 391 &point_in_view_coords); |
| 559 int hit_test = window_->non_client_view()->NonClientHitTest( | 392 int hit_test = window_->non_client_view()->NonClientHitTest( |
| 560 point_in_view_coords); | 393 point_in_view_coords); |
| 561 if (hit_test == HTCAPTION) { | 394 if (hit_test == HTCAPTION) { |
| 562 menu_runner_.reset(new views::MenuRunner(model.get())); | 395 menu_runner_.reset(new views::MenuRunner(model.get())); |
| 563 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL, | 396 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL, |
| 564 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT, | 397 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT, |
| 565 source_type, | 398 source_type, |
| 566 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 399 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 567 views::MenuRunner::MENU_DELETED) | 400 views::MenuRunner::MENU_DELETED) |
| 568 return; | 401 return; |
| 569 } | 402 } |
| 570 #endif | 403 #endif |
| 571 } | 404 } |
| 572 | 405 |
| 573 gfx::NativeView NativeAppWindowViews::GetHostView() const { | 406 // views::WidgetDelegate overrides: |
| 574 return window_->GetNativeView(); | |
| 575 } | |
| 576 | 407 |
| 577 gfx::Point NativeAppWindowViews::GetDialogPosition(const gfx::Size& size) { | 408 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { |
| 578 gfx::Size app_window_size = window_->GetWindowBoundsInScreen().size(); | 409 content::WebContents* web_contents = app_window()->web_contents(); |
| 579 return gfx::Point(app_window_size.width() / 2 - size.width() / 2, | |
| 580 app_window_size.height() / 2 - size.height() / 2); | |
| 581 } | |
| 582 | |
| 583 gfx::Size NativeAppWindowViews::GetMaximumDialogSize() { | |
| 584 return window_->GetWindowBoundsInScreen().size(); | |
| 585 } | |
| 586 | |
| 587 void NativeAppWindowViews::AddObserver( | |
| 588 web_modal::ModalDialogHostObserver* observer) { | |
| 589 observer_list_.AddObserver(observer); | |
| 590 } | |
| 591 void NativeAppWindowViews::RemoveObserver( | |
| 592 web_modal::ModalDialogHostObserver* observer) { | |
| 593 observer_list_.RemoveObserver(observer); | |
| 594 } | |
| 595 | |
| 596 // Private method. TODO(stevenjb): Move this below InitializePanelWindow() | |
| 597 // to match declaration order. | |
| 598 void NativeAppWindowViews::OnViewWasResized() { | |
| 599 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | |
| 600 observer_list_, | |
| 601 OnPositionRequiresUpdate()); | |
| 602 } | |
| 603 | |
| 604 // WidgetDelegate implementation. | |
| 605 | |
| 606 void NativeAppWindowViews::OnWidgetMove() { | |
| 607 app_window_->OnNativeWindowChanged(); | |
| 608 } | |
| 609 | |
| 610 views::View* NativeAppWindowViews::GetInitiallyFocusedView() { | |
| 611 return web_view_; | |
| 612 } | |
| 613 | |
| 614 bool NativeAppWindowViews::CanResize() const { | |
| 615 return resizable_ && !app_window_->size_constraints().HasFixedSize(); | |
| 616 } | |
| 617 | |
| 618 bool NativeAppWindowViews::CanMaximize() const { | |
| 619 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && | |
| 620 !app_window_->window_type_is_panel(); | |
| 621 } | |
| 622 | |
| 623 base::string16 NativeAppWindowViews::GetWindowTitle() const { | |
| 624 return app_window_->GetTitle(); | |
| 625 } | |
| 626 | |
| 627 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | |
| 628 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | |
| 629 } | |
| 630 | |
| 631 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { | |
| 632 gfx::Image app_icon = app_window_->app_icon(); | |
| 633 if (app_icon.IsEmpty()) | |
| 634 return GetWindowIcon(); | |
| 635 else | |
| 636 return *app_icon.ToImageSkia(); | |
| 637 } | |
| 638 | |
| 639 gfx::ImageSkia NativeAppWindowViews::GetWindowIcon() { | |
| 640 content::WebContents* web_contents = app_window_->web_contents(); | |
| 641 if (web_contents) { | 410 if (web_contents) { |
| 642 FaviconTabHelper* favicon_tab_helper = | 411 FaviconTabHelper* favicon_tab_helper = |
| 643 FaviconTabHelper::FromWebContents(web_contents); | 412 FaviconTabHelper::FromWebContents(web_contents); |
| 644 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | 413 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); |
| 645 if (!app_icon.IsEmpty()) | 414 if (!app_icon.IsEmpty()) |
| 646 return *app_icon.ToImageSkia(); | 415 return *app_icon.ToImageSkia(); |
| 647 } | 416 } |
| 648 return gfx::ImageSkia(); | 417 return gfx::ImageSkia(); |
| 649 } | 418 } |
| 650 | 419 |
| 651 bool NativeAppWindowViews::ShouldShowWindowIcon() const { | 420 views::NonClientFrameView* ChromeNativeAppWindowViews::CreateNonClientFrameView( |
| 652 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | |
| 653 } | |
| 654 | |
| 655 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | |
| 656 ui::WindowShowState show_state) { | |
| 657 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | |
| 658 app_window_->OnNativeWindowChanged(); | |
| 659 } | |
| 660 | |
| 661 void NativeAppWindowViews::DeleteDelegate() { | |
| 662 window_->RemoveObserver(this); | |
| 663 app_window_->OnNativeClose(); | |
| 664 } | |
| 665 | |
| 666 views::Widget* NativeAppWindowViews::GetWidget() { | |
| 667 return window_; | |
| 668 } | |
| 669 | |
| 670 const views::Widget* NativeAppWindowViews::GetWidget() const { | |
| 671 return window_; | |
| 672 } | |
| 673 | |
| 674 views::View* NativeAppWindowViews::GetContentsView() { | |
| 675 return this; | |
| 676 } | |
| 677 | |
| 678 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | |
| 679 views::Widget* widget) { | 421 views::Widget* widget) { |
| 680 #if defined(USE_ASH) | 422 #if defined(USE_ASH) |
| 681 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 423 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| 682 // Set the delegate now because CustomFrameViewAsh sets the | 424 // Set the delegate now because CustomFrameViewAsh sets the |
| 683 // WindowStateDelegate if one is not already set. | 425 // WindowStateDelegate if one is not already set. |
| 684 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | 426 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( |
| 685 scoped_ptr<ash::wm::WindowStateDelegate>( | 427 scoped_ptr<ash::wm::WindowStateDelegate>( |
| 686 new NativeAppWindowStateDelegate(app_window_, this)).Pass()); | 428 new NativeAppWindowStateDelegate(app_window(), this)).Pass()); |
| 687 | 429 |
| 688 if (app_window_->window_type_is_panel()) { | 430 if (app_window()->window_type_is_panel()) { |
| 689 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 431 ash::PanelFrameView::FrameType frame_type = IsFrameless() ? |
| 690 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 432 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 691 views::NonClientFrameView* frame_view = | 433 views::NonClientFrameView* frame_view = |
| 692 new ash::PanelFrameView(widget, frame_type); | 434 new ash::PanelFrameView(widget, frame_type); |
| 693 frame_view->set_context_menu_controller(this); | 435 frame_view->set_context_menu_controller(this); |
| 694 return frame_view; | 436 return frame_view; |
| 695 } | 437 } |
| 696 | 438 |
| 697 if (!frameless_) { | 439 if (!IsFrameless()) { |
| 698 ash::CustomFrameViewAsh* custom_frame_view = | 440 ash::CustomFrameViewAsh* custom_frame_view = |
| 699 new ash::CustomFrameViewAsh(widget); | 441 new ash::CustomFrameViewAsh(widget); |
| 700 #if defined(OS_CHROMEOS) | 442 #if defined(OS_CHROMEOS) |
| 701 // Non-frameless app windows can be put into immersive fullscreen. | 443 // Non-frameless app windows can be put into immersive fullscreen. |
| 702 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for | 444 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for |
| 703 // Windows Ash. | 445 // Windows Ash. |
| 704 if (ash::switches::UseImmersiveFullscreenForAllWindows()) { | 446 if (ash::switches::UseImmersiveFullscreenForAllWindows()) { |
| 705 immersive_fullscreen_controller_.reset( | 447 immersive_fullscreen_controller_.reset( |
| 706 new ash::ImmersiveFullscreenController()); | 448 new ash::ImmersiveFullscreenController()); |
| 707 custom_frame_view->InitImmersiveFullscreenControllerForView( | 449 custom_frame_view->InitImmersiveFullscreenControllerForView( |
| 708 immersive_fullscreen_controller_.get()); | 450 immersive_fullscreen_controller_.get()); |
| 709 } | 451 } |
| 710 #endif | 452 #endif |
| 711 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | 453 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); |
| 712 return custom_frame_view; | 454 return custom_frame_view; |
| 713 } | 455 } |
| 714 } | 456 } |
| 715 #endif | 457 #endif |
| 716 if (ShouldUseChromeStyleFrame()) | 458 if (ShouldUseChromeStyleFrame()) |
| 717 return CreateAppWindowFrameView(); | 459 return CreateAppWindowFrameView(); |
| 718 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 460 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 719 } | 461 } |
| 720 | 462 |
| 721 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 463 // views::View overrides: |
| 722 return shape_ != NULL; | 464 |
| 465 gfx::Size ChromeNativeAppWindowViews::GetPreferredSize() { |
| 466 if (!preferred_size_.IsEmpty()) |
| 467 return preferred_size_; |
| 468 return NativeAppWindowViews::GetPreferredSize(); |
| 723 } | 469 } |
| 724 | 470 |
| 725 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 471 bool ChromeNativeAppWindowViews::AcceleratorPressed( |
| 726 shape_->getBoundaryPath(mask); | |
| 727 } | |
| 728 | |
| 729 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( | |
| 730 gfx::NativeView child, | |
| 731 const gfx::Point& location) { | |
| 732 #if defined(USE_AURA) | |
| 733 if (child->Contains(web_view_->web_contents()->GetView()->GetNativeView())) { | |
| 734 // App window should claim mouse events that fall within the draggable | |
| 735 // region. | |
| 736 return !draggable_region_.get() || | |
| 737 !draggable_region_->contains(location.x(), location.y()); | |
| 738 } | |
| 739 #endif | |
| 740 | |
| 741 return true; | |
| 742 } | |
| 743 | |
| 744 // WidgetObserver implementation. | |
| 745 | |
| 746 void NativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget, | |
| 747 bool visible) { | |
| 748 app_window_->OnNativeWindowChanged(); | |
| 749 } | |
| 750 | |
| 751 void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget, | |
| 752 bool active) { | |
| 753 app_window_->OnNativeWindowChanged(); | |
| 754 if (active) | |
| 755 app_window_->OnNativeWindowActivated(); | |
| 756 } | |
| 757 | |
| 758 // WebContentsObserver implementation. | |
| 759 | |
| 760 void NativeAppWindowViews::RenderViewCreated( | |
| 761 content::RenderViewHost* render_view_host) { | |
| 762 if (transparent_background_) { | |
| 763 // Use a background with transparency to trigger transparency in Webkit. | |
| 764 SkBitmap background; | |
| 765 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | |
| 766 background.allocPixels(); | |
| 767 background.eraseARGB(0x00, 0x00, 0x00, 0x00); | |
| 768 | |
| 769 content::RenderWidgetHostView* view = render_view_host->GetView(); | |
| 770 DCHECK(view); | |
| 771 view->SetBackground(background); | |
| 772 } | |
| 773 } | |
| 774 | |
| 775 void NativeAppWindowViews::RenderViewHostChanged( | |
| 776 content::RenderViewHost* old_host, | |
| 777 content::RenderViewHost* new_host) { | |
| 778 OnViewWasResized(); | |
| 779 } | |
| 780 | |
| 781 // views::View implementation. | |
| 782 | |
| 783 void NativeAppWindowViews::Layout() { | |
| 784 DCHECK(web_view_); | |
| 785 web_view_->SetBounds(0, 0, width(), height()); | |
| 786 OnViewWasResized(); | |
| 787 } | |
| 788 | |
| 789 void NativeAppWindowViews::ViewHierarchyChanged( | |
| 790 const ViewHierarchyChangedDetails& details) { | |
| 791 if (details.is_add && details.child == this) { | |
| 792 web_view_ = new views::WebView(NULL); | |
| 793 AddChildView(web_view_); | |
| 794 web_view_->SetWebContents(web_contents()); | |
| 795 } | |
| 796 } | |
| 797 | |
| 798 gfx::Size NativeAppWindowViews::GetPreferredSize() { | |
| 799 if (!preferred_size_.IsEmpty()) | |
| 800 return preferred_size_; | |
| 801 return views::View::GetPreferredSize(); | |
| 802 } | |
| 803 | |
| 804 gfx::Size NativeAppWindowViews::GetMinimumSize() { | |
| 805 return app_window_->size_constraints().GetMinimumSize(); | |
| 806 } | |
| 807 | |
| 808 gfx::Size NativeAppWindowViews::GetMaximumSize() { | |
| 809 return app_window_->size_constraints().GetMaximumSize(); | |
| 810 } | |
| 811 | |
| 812 void NativeAppWindowViews::OnFocus() { | |
| 813 web_view_->RequestFocus(); | |
| 814 } | |
| 815 | |
| 816 bool NativeAppWindowViews::AcceleratorPressed( | |
| 817 const ui::Accelerator& accelerator) { | 472 const ui::Accelerator& accelerator) { |
| 818 const std::map<ui::Accelerator, int>& accelerator_table = | 473 const std::map<ui::Accelerator, int>& accelerator_table = |
| 819 GetAcceleratorTable(); | 474 GetAcceleratorTable(); |
| 820 std::map<ui::Accelerator, int>::const_iterator iter = | 475 std::map<ui::Accelerator, int>::const_iterator iter = |
| 821 accelerator_table.find(accelerator); | 476 accelerator_table.find(accelerator); |
| 822 DCHECK(iter != accelerator_table.end()); | 477 DCHECK(iter != accelerator_table.end()); |
| 823 int command_id = iter->second; | 478 int command_id = iter->second; |
| 824 switch (command_id) { | 479 switch (command_id) { |
| 825 case IDC_CLOSE_WINDOW: | 480 case IDC_CLOSE_WINDOW: |
| 826 Close(); | 481 Close(); |
| 827 return true; | 482 return true; |
| 828 case IDC_ZOOM_MINUS: | 483 case IDC_ZOOM_MINUS: |
| 829 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | 484 chrome_page_zoom::Zoom(web_view()->GetWebContents(), |
| 830 content::PAGE_ZOOM_OUT); | 485 content::PAGE_ZOOM_OUT); |
| 831 return true; | 486 return true; |
| 832 case IDC_ZOOM_NORMAL: | 487 case IDC_ZOOM_NORMAL: |
| 833 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | 488 chrome_page_zoom::Zoom(web_view()->GetWebContents(), |
| 834 content::PAGE_ZOOM_RESET); | 489 content::PAGE_ZOOM_RESET); |
| 835 return true; | 490 return true; |
| 836 case IDC_ZOOM_PLUS: | 491 case IDC_ZOOM_PLUS: |
| 837 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | 492 chrome_page_zoom::Zoom(web_view()->GetWebContents(), |
| 838 content::PAGE_ZOOM_IN); | 493 content::PAGE_ZOOM_IN); |
| 839 return true; | 494 return true; |
| 840 default: | 495 default: |
| 841 NOTREACHED() << "Unknown accelerator sent to app window."; | 496 NOTREACHED() << "Unknown accelerator sent to app window."; |
| 842 } | 497 } |
| 843 return false; | 498 return NativeAppWindowViews::AcceleratorPressed(accelerator); |
| 844 } | 499 } |
| 845 | 500 |
| 846 // NativeAppWindow implementation. | 501 // NativeAppWindow overrides: |
| 847 | 502 |
| 848 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { | 503 void ChromeNativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| 849 // Fullscreen not supported by panels. | 504 // Fullscreen not supported by panels. |
| 850 if (app_window_->window_type_is_panel()) | 505 if (app_window()->window_type_is_panel()) |
| 851 return; | 506 return; |
| 852 is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | 507 is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
| 853 window_->SetFullscreen(is_fullscreen_); | 508 window()->SetFullscreen(is_fullscreen_); |
| 854 | 509 |
| 855 #if defined(USE_ASH) | 510 #if defined(USE_ASH) |
| 856 if (immersive_fullscreen_controller_.get()) { | 511 if (immersive_fullscreen_controller_.get()) { |
| 857 // |immersive_fullscreen_controller_| should only be set if immersive | 512 // |immersive_fullscreen_controller_| should only be set if immersive |
| 858 // fullscreen is the fullscreen type used by the OS. | 513 // fullscreen is the fullscreen type used by the OS. |
| 859 immersive_fullscreen_controller_->SetEnabled( | 514 immersive_fullscreen_controller_->SetEnabled( |
| 860 ash::ImmersiveFullscreenController::WINDOW_TYPE_PACKAGED_APP, | 515 ash::ImmersiveFullscreenController::WINDOW_TYPE_PACKAGED_APP, |
| 861 (fullscreen_types & AppWindow::FULLSCREEN_TYPE_OS) != 0); | 516 (fullscreen_types & AppWindow::FULLSCREEN_TYPE_OS) != 0); |
| 862 // Autohide the shelf instead of hiding the shelf completely when only in | 517 // Autohide the shelf instead of hiding the shelf completely when only in |
| 863 // OS fullscreen. | 518 // OS fullscreen. |
| 864 ash::wm::WindowState* window_state = | 519 ash::wm::WindowState* window_state = |
| 865 ash::wm::GetWindowState(window_->GetNativeWindow()); | 520 ash::wm::GetWindowState(window()->GetNativeWindow()); |
| 866 window_state->set_hide_shelf_when_fullscreen(fullscreen_types != | 521 window_state->set_hide_shelf_when_fullscreen(fullscreen_types != |
| 867 AppWindow::FULLSCREEN_TYPE_OS); | 522 AppWindow::FULLSCREEN_TYPE_OS); |
| 868 DCHECK(ash::Shell::HasInstance()); | 523 DCHECK(ash::Shell::HasInstance()); |
| 869 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 524 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| 870 } | 525 } |
| 871 #endif | 526 #endif |
| 872 | 527 |
| 873 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 528 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 874 // ever drop the window out of fullscreen in response to something that | 529 // ever drop the window out of fullscreen in response to something that |
| 875 // wasn't the app calling webkitCancelFullScreen(). | 530 // wasn't the app calling webkitCancelFullScreen(). |
| 876 } | 531 } |
| 877 | 532 |
| 878 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 533 bool ChromeNativeAppWindowViews::IsFullscreenOrPending() const { |
| 879 return is_fullscreen_; | 534 return is_fullscreen_; |
| 880 } | 535 } |
| 881 | 536 |
| 882 bool NativeAppWindowViews::IsDetached() const { | 537 bool ChromeNativeAppWindowViews::IsDetached() const { |
| 883 if (!app_window_->window_type_is_panel()) | 538 if (!app_window()->window_type_is_panel()) |
| 884 return false; | 539 return false; |
| 885 #if defined(USE_ASH) | 540 #if defined(USE_ASH) |
| 886 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); | 541 return !ash::wm::GetWindowState(window()->GetNativeWindow())->panel_attached()
; |
| 887 #else | 542 #else |
| 888 return false; | 543 return false; |
| 889 #endif | 544 #endif |
| 890 } | 545 } |
| 891 | 546 |
| 892 void NativeAppWindowViews::UpdateWindowIcon() { | 547 void ChromeNativeAppWindowViews::UpdateBadgeIcon() { |
| 893 window_->UpdateWindowIcon(); | |
| 894 } | |
| 895 | |
| 896 void NativeAppWindowViews::UpdateWindowTitle() { | |
| 897 window_->UpdateWindowTitle(); | |
| 898 } | |
| 899 | |
| 900 void NativeAppWindowViews::UpdateBadgeIcon() { | |
| 901 const gfx::Image* icon = NULL; | 548 const gfx::Image* icon = NULL; |
| 902 if (!app_window_->badge_icon().IsEmpty()) { | 549 if (!app_window()->badge_icon().IsEmpty()) { |
| 903 icon = &app_window_->badge_icon(); | 550 icon = &app_window()->badge_icon(); |
| 904 // chrome::DrawTaskbarDecoration can do interesting things with non-square | 551 // chrome::DrawTaskbarDecoration can do interesting things with non-square |
| 905 // bitmaps. | 552 // bitmaps. |
| 906 // TODO(benwells): Refactor chrome::DrawTaskbarDecoration to not be avatar | 553 // TODO(benwells): Refactor chrome::DrawTaskbarDecoration to not be avatar |
| 907 // specific, and lift this restriction. | 554 // specific, and lift this restriction. |
| 908 if (icon->Width() != icon->Height()) { | 555 if (icon->Width() != icon->Height()) { |
| 909 LOG(ERROR) << "Attempt to set a non-square badge; request ignored."; | 556 LOG(ERROR) << "Attempt to set a non-square badge; request ignored."; |
| 910 return; | 557 return; |
| 911 } | 558 } |
| 912 } | 559 } |
| 913 chrome::DrawTaskbarDecoration(GetNativeWindow(), icon); | 560 chrome::DrawTaskbarDecoration(GetNativeWindow(), icon); |
| 914 } | 561 } |
| 915 | 562 |
| 916 void NativeAppWindowViews::UpdateDraggableRegions( | 563 // NativeAppWindowViews overrides: |
| 917 const std::vector<extensions::DraggableRegion>& regions) { | |
| 918 // Draggable region is not supported for non-frameless window. | |
| 919 if (!frameless_) | |
| 920 return; | |
| 921 | 564 |
| 922 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); | 565 void ChromeNativeAppWindowViews::InitializeWindow( |
| 923 OnViewWasResized(); | 566 AppWindow* app_window, |
| 567 const AppWindow::CreateParams& create_params) { |
| 568 DCHECK(window()); |
| 569 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || |
| 570 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { |
| 571 InitializePanelWindow(create_params); |
| 572 } else { |
| 573 InitializeDefaultWindow(create_params); |
| 574 } |
| 575 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 576 Profile::FromBrowserContext(browser_context()), |
| 577 window()->GetFocusManager(), |
| 578 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| 579 app_window)); |
| 924 } | 580 } |
| 925 | 581 |
| 926 SkRegion* NativeAppWindowViews::GetDraggableRegion() { | 582 // private methods: |
| 927 return draggable_region_.get(); | 583 |
| 584 bool ChromeNativeAppWindowViews::ShouldUseChromeStyleFrame() const { |
| 585 if (IsFrameless()) |
| 586 return true; |
| 587 |
| 588 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 589 // Linux always uses native style frames. |
| 590 return false; |
| 591 #endif |
| 592 |
| 593 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 594 switches::kAppsUseNativeFrame); |
| 928 } | 595 } |
| 929 | 596 |
| 930 void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { | 597 apps::AppWindowFrameView* |
| 931 bool had_shape = shape_; | 598 ChromeNativeAppWindowViews::CreateAppWindowFrameView() { |
| 932 shape_ = region.Pass(); | 599 // By default the user can resize the window from slightly inside the bounds. |
| 933 | 600 int resize_inside_bounds_size = kResizeInsideBoundsSize; |
| 934 aura::Window* native_window = window_->GetNativeWindow(); | 601 int resize_outside_bounds_size = 0; |
| 935 if (shape_) { | 602 int resize_outside_scale_for_touch = 1; |
| 936 window_->SetShape(new SkRegion(*shape_)); | 603 int resize_area_corner_size = kResizeAreaCornerSize; |
| 937 if (!had_shape) { | 604 #if defined(USE_ASH) |
| 938 native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | 605 // For Aura windows on the Ash desktop the sizes are different and the user |
| 939 new ShapedAppWindowTargeter(native_window, this))); | 606 // can resize the window from slightly outside the bounds as well. |
| 940 } | 607 if (chrome::IsNativeWindowInAsh(window()->GetNativeWindow())) { |
| 941 } else { | 608 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; |
| 942 window_->SetShape(NULL); | 609 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; |
| 943 if (had_shape) | 610 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; |
| 944 native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); | 611 resize_area_corner_size = ash::kResizeAreaCornerSize; |
| 945 } | 612 } |
| 613 #endif |
| 614 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); |
| 615 frame_view->Init(window(), |
| 616 resize_inside_bounds_size, |
| 617 resize_outside_bounds_size, |
| 618 resize_outside_scale_for_touch, |
| 619 resize_area_corner_size); |
| 620 return frame_view; |
| 946 } | 621 } |
| 947 | |
| 948 void NativeAppWindowViews::HandleKeyboardEvent( | |
| 949 const content::NativeWebKeyboardEvent& event) { | |
| 950 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | |
| 951 GetFocusManager()); | |
| 952 } | |
| 953 | |
| 954 bool NativeAppWindowViews::IsFrameless() const { | |
| 955 return frameless_; | |
| 956 } | |
| 957 | |
| 958 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | |
| 959 if (frameless_) | |
| 960 return gfx::Insets(); | |
| 961 | |
| 962 // The pretend client_bounds passed in need to be large enough to ensure that | |
| 963 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | |
| 964 // the specified amount of space to fit the window controls in, and return a | |
| 965 // number larger than the real frame insets. Most window controls are smaller | |
| 966 // than 1000x1000px, so this should be big enough. | |
| 967 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | |
| 968 gfx::Rect window_bounds = | |
| 969 window_->non_client_view()->GetWindowBoundsForClientBounds( | |
| 970 client_bounds); | |
| 971 return window_bounds.InsetsFrom(client_bounds); | |
| 972 } | |
| 973 | |
| 974 void NativeAppWindowViews::HideWithApp() {} | |
| 975 void NativeAppWindowViews::ShowWithApp() {} | |
| 976 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | |
| OLD | NEW |