Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 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/chrome_native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/ui/views/app_window_frame_view.h" | 7 #include "apps/ui/views/app_window_frame_view.h" |
| 8 #include "base/command_line.h" | |
| 9 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/app_mode/app_mode_utils.h" | 9 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 10 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/host_desktop.h" | |
| 14 #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h" | 12 #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h" |
| 15 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | |
| 16 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 13 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
| 17 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 14 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
| 18 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
| 19 #include "chrome/common/chrome_switches.h" | |
| 20 #include "components/ui/zoom/page_zoom.h" | 16 #include "components/ui/zoom/page_zoom.h" |
| 21 #include "components/ui/zoom/zoom_controller.h" | 17 #include "components/ui/zoom/zoom_controller.h" |
| 22 #include "extensions/common/extension.h" | |
| 23 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
|
tapted
2015/02/25 05:54:35
remove? there might be some strays still...
jackhou1
2015/02/25 22:57:51
Done.
| |
| 24 #include "ui/base/hit_test.h" | |
| 25 #include "ui/base/models/simple_menu_model.h" | |
| 26 #include "ui/gfx/image/image_skia.h" | |
| 27 #include "ui/views/controls/menu/menu_runner.h" | |
| 28 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
| 29 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 30 #include "ui/wm/core/easy_resize_window_targeter.h" | |
| 31 | 21 |
| 32 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
| 33 #include "chrome/browser/shell_integration_linux.h" | 23 #include "chrome/browser/shell_integration_linux.h" |
| 34 #endif | 24 #endif |
| 35 | 25 |
| 36 #if defined(USE_ASH) | |
| 37 #include "ash/ash_constants.h" | |
| 38 #include "ash/ash_switches.h" | |
| 39 #include "ash/frame/custom_frame_view_ash.h" | |
| 40 #include "ash/screen_util.h" | |
| 41 #include "ash/shell.h" | |
| 42 #include "ash/wm/immersive_fullscreen_controller.h" | |
| 43 #include "ash/wm/panels/panel_frame_view.h" | |
| 44 #include "ash/wm/window_properties.h" | |
| 45 #include "ash/wm/window_state.h" | |
| 46 #include "ash/wm/window_state_delegate.h" | |
| 47 #include "ash/wm/window_state_observer.h" | |
| 48 #include "chrome/browser/ui/ash/ash_util.h" | |
| 49 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" | |
| 50 #include "ui/aura/client/aura_constants.h" | |
| 51 #include "ui/aura/client/window_tree_client.h" | |
| 52 #include "ui/aura/window_observer.h" | |
| 53 #endif | |
| 54 | |
| 55 #if defined(OS_CHROMEOS) | |
| 56 #include "ash/shell_window_ids.h" | |
| 57 #endif | |
| 58 | |
| 59 using extensions::AppWindow; | 26 using extensions::AppWindow; |
| 60 | 27 |
| 61 namespace { | 28 namespace { |
| 62 | 29 |
| 63 const int kMinPanelWidth = 100; | 30 const int kMinPanelWidth = 100; |
| 64 const int kMinPanelHeight = 100; | 31 const int kMinPanelHeight = 100; |
| 65 const int kDefaultPanelWidth = 200; | 32 const int kDefaultPanelWidth = 200; |
| 66 const int kDefaultPanelHeight = 300; | 33 const int kDefaultPanelHeight = 300; |
| 67 | 34 |
| 68 struct AcceleratorMapping { | 35 struct AcceleratorMapping { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 if (chrome::IsRunningInForcedAppMode()) { | 82 if (chrome::IsRunningInForcedAppMode()) { |
| 116 AddAcceleratorsFromMapping( | 83 AddAcceleratorsFromMapping( |
| 117 kAppWindowKioskAppModeAcceleratorMap, | 84 kAppWindowKioskAppModeAcceleratorMap, |
| 118 arraysize(kAppWindowKioskAppModeAcceleratorMap), | 85 arraysize(kAppWindowKioskAppModeAcceleratorMap), |
| 119 &accelerators); | 86 &accelerators); |
| 120 } | 87 } |
| 121 } | 88 } |
| 122 return accelerators; | 89 return accelerators; |
| 123 } | 90 } |
| 124 | 91 |
| 125 #if defined(USE_ASH) | |
| 126 // This class handles a user's fullscreen request (Shift+F4/F4). | |
| 127 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, | |
| 128 public ash::wm::WindowStateObserver, | |
| 129 public aura::WindowObserver { | |
| 130 public: | |
| 131 NativeAppWindowStateDelegate(AppWindow* app_window, | |
| 132 extensions::NativeAppWindow* native_app_window) | |
| 133 : app_window_(app_window), | |
| 134 window_state_( | |
| 135 ash::wm::GetWindowState(native_app_window->GetNativeWindow())) { | |
| 136 // Add a window state observer to exit fullscreen properly in case | |
| 137 // fullscreen is exited without going through AppWindow::Restore(). This | |
| 138 // is the case when exiting immersive fullscreen via the "Restore" window | |
| 139 // control. | |
| 140 // TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048 | |
| 141 window_state_->AddObserver(this); | |
| 142 window_state_->window()->AddObserver(this); | |
| 143 } | |
| 144 ~NativeAppWindowStateDelegate() override { | |
| 145 if (window_state_) { | |
| 146 window_state_->RemoveObserver(this); | |
| 147 window_state_->window()->RemoveObserver(this); | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 private: | |
| 152 // Overridden from ash::wm::WindowStateDelegate. | |
| 153 bool ToggleFullscreen(ash::wm::WindowState* window_state) override { | |
| 154 // Windows which cannot be maximized should not be fullscreened. | |
| 155 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); | |
| 156 if (window_state->IsFullscreen()) | |
| 157 app_window_->Restore(); | |
| 158 else if (window_state->CanMaximize()) | |
| 159 app_window_->OSFullscreen(); | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 163 // Overridden from ash::wm::WindowStateObserver: | |
| 164 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, | |
| 165 ash::wm::WindowStateType old_type) override { | |
| 166 // Since the window state might get set by a window manager, it is possible | |
| 167 // to come here before the application set its |BaseWindow|. | |
| 168 if (!window_state->IsFullscreen() && !window_state->IsMinimized() && | |
| 169 app_window_->GetBaseWindow() && | |
| 170 app_window_->GetBaseWindow()->IsFullscreenOrPending()) { | |
| 171 app_window_->Restore(); | |
| 172 // Usually OnNativeWindowChanged() is called when the window bounds are | |
| 173 // changed as a result of a state type change. Because the change in state | |
| 174 // type has already occurred, we need to call OnNativeWindowChanged() | |
| 175 // explicitly. | |
| 176 app_window_->OnNativeWindowChanged(); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 // Overridden from aura::WindowObserver: | |
| 181 void OnWindowDestroying(aura::Window* window) override { | |
| 182 window_state_->RemoveObserver(this); | |
| 183 window_state_->window()->RemoveObserver(this); | |
| 184 window_state_ = NULL; | |
| 185 } | |
| 186 | |
| 187 // Not owned. | |
| 188 AppWindow* app_window_; | |
| 189 ash::wm::WindowState* window_state_; | |
| 190 | |
| 191 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | |
| 192 }; | |
| 193 #endif // USE_ASH | |
| 194 | |
| 195 } // namespace | 92 } // namespace |
| 196 | 93 |
| 197 ChromeNativeAppWindowViews::ChromeNativeAppWindowViews() | 94 ChromeNativeAppWindowViews::ChromeNativeAppWindowViews() |
| 198 : is_fullscreen_(false), | 95 : is_fullscreen_(false), |
| 199 has_frame_color_(false), | 96 has_frame_color_(false), |
| 200 active_frame_color_(SK_ColorBLACK), | 97 active_frame_color_(SK_ColorBLACK), |
| 201 inactive_frame_color_(SK_ColorBLACK) { | 98 inactive_frame_color_(SK_ColorBLACK) { |
| 202 } | 99 } |
| 203 | 100 |
| 204 ChromeNativeAppWindowViews::~ChromeNativeAppWindowViews() {} | 101 ChromeNativeAppWindowViews::~ChromeNativeAppWindowViews() {} |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); | 133 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); |
| 237 init_params.wm_class_class = shell_integration_linux::GetProgramClassName(); | 134 init_params.wm_class_class = shell_integration_linux::GetProgramClassName(); |
| 238 const char kX11WindowRoleApp[] = "app"; | 135 const char kX11WindowRoleApp[] = "app"; |
| 239 init_params.wm_role_name = std::string(kX11WindowRoleApp); | 136 init_params.wm_role_name = std::string(kX11WindowRoleApp); |
| 240 #endif | 137 #endif |
| 241 | 138 |
| 242 OnBeforeWidgetInit(&init_params, widget()); | 139 OnBeforeWidgetInit(&init_params, widget()); |
| 243 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
| 244 if (create_params.is_ime_window) { | 141 if (create_params.is_ime_window) { |
| 245 // Puts ime windows into ime window container. | 142 // Puts ime windows into ime window container. |
| 246 init_params.parent = | 143 init_params.parent = GetImeWindowContainer(); |
|
tapted
2015/02/25 05:54:35
can you just override OnBeforeWidgetInit to do thi
jackhou1
2015/02/25 22:57:51
This needs create_params.is_ime_window. I made it
tapted
2015/02/25 23:28:09
It's nice :).
| |
| 247 ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), | |
| 248 ash::kShellWindowId_ImeWindowParentContainer); | |
| 249 } | 144 } |
| 250 #endif | 145 #endif |
| 251 widget()->Init(init_params); | 146 widget()->Init(init_params); |
| 252 | 147 |
| 253 // The frame insets are required to resolve the bounds specifications | 148 // The frame insets are required to resolve the bounds specifications |
| 254 // correctly. So we set the window bounds and constraints now. | 149 // correctly. So we set the window bounds and constraints now. |
| 255 gfx::Insets frame_insets = GetFrameInsets(); | 150 gfx::Insets frame_insets = GetFrameInsets(); |
| 256 gfx::Rect window_bounds = create_params.GetInitialWindowBounds(frame_insets); | 151 gfx::Rect window_bounds = create_params.GetInitialWindowBounds(frame_insets); |
| 257 SetContentSizeConstraints(create_params.GetContentMinimumSize(frame_insets), | 152 SetContentSizeConstraints(create_params.GetContentMinimumSize(frame_insets), |
| 258 create_params.GetContentMaximumSize(frame_insets)); | 153 create_params.GetContentMaximumSize(frame_insets)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 accelerator_table.begin(); | 193 accelerator_table.begin(); |
| 299 iter != accelerator_table.end(); ++iter) { | 194 iter != accelerator_table.end(); ++iter) { |
| 300 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) | 195 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) |
| 301 continue; | 196 continue; |
| 302 | 197 |
| 303 focus_manager->RegisterAccelerator( | 198 focus_manager->RegisterAccelerator( |
| 304 iter->first, ui::AcceleratorManager::kNormalPriority, this); | 199 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
| 305 } | 200 } |
| 306 } | 201 } |
| 307 | 202 |
| 203 gfx::NativeView ChromeNativeAppWindowViews::GetImeWindowContainer() { | |
| 204 return nullptr; | |
| 205 } | |
| 206 | |
| 308 void ChromeNativeAppWindowViews::InitializePanelWindow( | 207 void ChromeNativeAppWindowViews::InitializePanelWindow( |
| 309 const AppWindow::CreateParams& create_params) { | 208 const AppWindow::CreateParams& create_params) { |
| 310 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 209 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
| 311 params.delegate = this; | 210 params.delegate = this; |
| 312 | 211 |
| 313 gfx::Rect initial_window_bounds = | 212 gfx::Rect initial_window_bounds = |
| 314 create_params.GetInitialWindowBounds(gfx::Insets()); | 213 create_params.GetInitialWindowBounds(gfx::Insets()); |
| 315 preferred_size_ = gfx::Size(initial_window_bounds.width(), | 214 preferred_size_ = gfx::Size(initial_window_bounds.width(), |
| 316 initial_window_bounds.height()); | 215 initial_window_bounds.height()); |
| 317 if (preferred_size_.width() == 0) | 216 if (preferred_size_.width() == 0) |
| 318 preferred_size_.set_width(kDefaultPanelWidth); | 217 preferred_size_.set_width(kDefaultPanelWidth); |
| 319 else if (preferred_size_.width() < kMinPanelWidth) | 218 else if (preferred_size_.width() < kMinPanelWidth) |
| 320 preferred_size_.set_width(kMinPanelWidth); | 219 preferred_size_.set_width(kMinPanelWidth); |
| 321 | 220 |
| 322 if (preferred_size_.height() == 0) | 221 if (preferred_size_.height() == 0) |
| 323 preferred_size_.set_height(kDefaultPanelHeight); | 222 preferred_size_.set_height(kDefaultPanelHeight); |
| 324 else if (preferred_size_.height() < kMinPanelHeight) | 223 else if (preferred_size_.height() < kMinPanelHeight) |
| 325 preferred_size_.set_height(kMinPanelHeight); | 224 preferred_size_.set_height(kMinPanelHeight); |
| 326 #if defined(USE_ASH) | 225 |
| 327 if (ash::Shell::HasInstance()) { | 226 params.bounds = GetPanelWindowInitialBounds(preferred_size_); |
| 328 // Open a new panel on the target root. | |
| 329 aura::Window* target = ash::Shell::GetTargetRootWindow(); | |
| 330 params.bounds = ash::ScreenUtil::ConvertRectToScreen( | |
| 331 target, gfx::Rect(preferred_size_)); | |
| 332 } else { | |
| 333 params.bounds = gfx::Rect(preferred_size_); | |
| 334 } | |
| 335 #else | |
| 336 params.bounds = gfx::Rect(preferred_size_); | |
| 337 #endif | |
| 338 widget()->Init(params); | 227 widget()->Init(params); |
|
tapted
2015/02/25 05:54:35
for this, perhaps just add a OnBeforePanelWidgetIn
jackhou1
2015/02/25 22:57:51
Done.
| |
| 339 widget()->set_focus_on_creation(create_params.focused); | 228 widget()->set_focus_on_creation(create_params.focused); |
| 340 } | 229 } |
| 341 | 230 |
| 231 gfx::Rect ChromeNativeAppWindowViews::GetPanelWindowInitialBounds( | |
| 232 gfx::Size preferred_size_) { | |
| 233 return gfx::Rect(preferred_size_); | |
| 234 } | |
| 235 | |
| 342 views::NonClientFrameView* | 236 views::NonClientFrameView* |
| 343 ChromeNativeAppWindowViews::CreateStandardDesktopAppFrame() { | 237 ChromeNativeAppWindowViews::CreateStandardDesktopAppFrame() { |
| 344 return views::WidgetDelegateView::CreateNonClientFrameView(widget()); | 238 return views::WidgetDelegateView::CreateNonClientFrameView(widget()); |
| 345 } | 239 } |
| 346 | 240 |
| 241 apps::AppWindowFrameView* | |
| 242 ChromeNativeAppWindowViews::CreateNonStandardAppFrame() { | |
| 243 apps::AppWindowFrameView* frame = | |
| 244 new apps::AppWindowFrameView(widget(), this, has_frame_color_, | |
| 245 active_frame_color_, inactive_frame_color_); | |
| 246 frame->Init(); | |
| 247 return frame; | |
| 248 } | |
| 249 | |
| 347 // ui::BaseWindow implementation. | 250 // ui::BaseWindow implementation. |
| 348 | 251 |
| 349 gfx::Rect ChromeNativeAppWindowViews::GetRestoredBounds() const { | 252 gfx::Rect ChromeNativeAppWindowViews::GetRestoredBounds() const { |
| 350 #if defined(USE_ASH) | |
| 351 gfx::Rect* bounds = widget()->GetNativeWindow()->GetProperty( | |
| 352 ash::kRestoreBoundsOverrideKey); | |
| 353 if (bounds && !bounds->IsEmpty()) | |
| 354 return *bounds; | |
| 355 #endif | |
| 356 return widget()->GetRestoredBounds(); | 253 return widget()->GetRestoredBounds(); |
| 357 } | 254 } |
| 358 | 255 |
| 359 ui::WindowShowState ChromeNativeAppWindowViews::GetRestoredState() const { | 256 ui::WindowShowState ChromeNativeAppWindowViews::GetRestoredState() const { |
| 360 #if !defined(USE_ASH) | |
| 361 if (IsMaximized()) | 257 if (IsMaximized()) |
| 362 return ui::SHOW_STATE_MAXIMIZED; | 258 return ui::SHOW_STATE_MAXIMIZED; |
|
tapted
2015/02/25 05:54:35
hm - this line is essentially dead -- #ifdef'd out
| |
| 363 if (IsFullscreen()) | 259 if (IsFullscreen()) |
| 364 return ui::SHOW_STATE_FULLSCREEN; | 260 return ui::SHOW_STATE_FULLSCREEN; |
| 365 #else | |
| 366 // Use kRestoreShowStateKey in case a window is minimized/hidden. | |
| 367 ui::WindowShowState restore_state = widget()->GetNativeWindow()->GetProperty( | |
| 368 aura::client::kRestoreShowStateKey); | |
| 369 if (widget()->GetNativeWindow()->GetProperty( | |
| 370 ash::kRestoreBoundsOverrideKey)) { | |
| 371 // If an override is given, we use that restore state (after filtering). | |
| 372 restore_state = widget()->GetNativeWindow()->GetProperty( | |
| 373 ash::kRestoreShowStateOverrideKey); | |
| 374 } else { | |
| 375 // Otherwise first normal states are checked. | |
| 376 if (IsMaximized()) | |
| 377 return ui::SHOW_STATE_MAXIMIZED; | |
| 378 if (IsFullscreen()) { | |
| 379 if (immersive_fullscreen_controller_.get() && | |
| 380 immersive_fullscreen_controller_->IsEnabled()) { | |
| 381 // Restore windows which were previously in immersive fullscreen to | |
| 382 // maximized. Restoring the window to a different fullscreen type | |
| 383 // makes for a bad experience. | |
| 384 return ui::SHOW_STATE_MAXIMIZED; | |
| 385 } | |
| 386 return ui::SHOW_STATE_FULLSCREEN; | |
| 387 } | |
| 388 } | |
| 389 // Whitelist states to return so that invalid and transient states | |
| 390 // are not saved and used to restore windows when they are recreated. | |
| 391 switch (restore_state) { | |
| 392 case ui::SHOW_STATE_NORMAL: | |
| 393 case ui::SHOW_STATE_MAXIMIZED: | |
| 394 case ui::SHOW_STATE_FULLSCREEN: | |
| 395 return restore_state; | |
| 396 | 261 |
| 397 case ui::SHOW_STATE_DEFAULT: | |
| 398 case ui::SHOW_STATE_MINIMIZED: | |
| 399 case ui::SHOW_STATE_INACTIVE: | |
| 400 case ui::SHOW_STATE_END: | |
| 401 return ui::SHOW_STATE_NORMAL; | |
| 402 } | |
| 403 #endif // !defined(USE_ASH) | |
| 404 return ui::SHOW_STATE_NORMAL; | 262 return ui::SHOW_STATE_NORMAL; |
| 405 } | 263 } |
| 406 | 264 |
| 407 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { | 265 bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { |
| 408 if (app_window()->window_type_is_panel()) { | 266 return app_window()->window_type_is_panel() || widget()->IsAlwaysOnTop(); |
|
tapted
2015/02/25 05:54:35
hm - not sure this is right for Mac -- maybe add a
jackhou1
2015/02/25 22:57:51
Added TODO.
| |
| 409 #if defined(USE_ASH) | |
| 410 return ash::wm::GetWindowState(widget()->GetNativeWindow()) | |
| 411 ->panel_attached(); | |
| 412 #else | |
| 413 return true; | |
| 414 #endif | |
| 415 } else { | |
| 416 return widget()->IsAlwaysOnTop(); | |
| 417 } | |
| 418 } | |
| 419 | |
| 420 // views::ContextMenuController implementation. | |
| 421 | |
| 422 void ChromeNativeAppWindowViews::ShowContextMenuForView( | |
| 423 views::View* source, | |
| 424 const gfx::Point& p, | |
| 425 ui::MenuSourceType source_type) { | |
| 426 #if defined(USE_ASH) && defined(OS_CHROMEOS) | |
| 427 scoped_ptr<ui::MenuModel> model = | |
| 428 CreateMultiUserContextMenu(app_window()->GetNativeWindow()); | |
| 429 if (!model.get()) | |
| 430 return; | |
| 431 | |
| 432 // Only show context menu if point is in caption. | |
| 433 gfx::Point point_in_view_coords(p); | |
| 434 views::View::ConvertPointFromScreen(widget()->non_client_view(), | |
| 435 &point_in_view_coords); | |
| 436 int hit_test = | |
| 437 widget()->non_client_view()->NonClientHitTest(point_in_view_coords); | |
| 438 if (hit_test == HTCAPTION) { | |
| 439 menu_runner_.reset(new views::MenuRunner( | |
| 440 model.get(), | |
| 441 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); | |
| 442 if (menu_runner_->RunMenuAt(source->GetWidget(), | |
| 443 NULL, | |
| 444 gfx::Rect(p, gfx::Size(0, 0)), | |
| 445 views::MENU_ANCHOR_TOPLEFT, | |
| 446 source_type) == | |
| 447 views::MenuRunner::MENU_DELETED) { | |
| 448 return; | |
| 449 } | |
| 450 } | |
| 451 #endif | |
| 452 } | 267 } |
| 453 | 268 |
| 454 // views::WidgetDelegate implementation. | 269 // views::WidgetDelegate implementation. |
| 455 | 270 |
| 456 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() { | 271 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowAppIcon() { |
| 457 gfx::Image app_icon = app_window()->app_icon(); | 272 gfx::Image app_icon = app_window()->app_icon(); |
| 458 if (app_icon.IsEmpty()) | 273 if (app_icon.IsEmpty()) |
| 459 return GetWindowIcon(); | 274 return GetWindowIcon(); |
| 460 else | 275 else |
| 461 return *app_icon.ToImageSkia(); | 276 return *app_icon.ToImageSkia(); |
| 462 } | 277 } |
| 463 | 278 |
| 464 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { | 279 gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { |
| 465 content::WebContents* web_contents = app_window()->web_contents(); | 280 content::WebContents* web_contents = app_window()->web_contents(); |
| 466 if (web_contents) { | 281 if (web_contents) { |
| 467 FaviconTabHelper* favicon_tab_helper = | 282 FaviconTabHelper* favicon_tab_helper = |
| 468 FaviconTabHelper::FromWebContents(web_contents); | 283 FaviconTabHelper::FromWebContents(web_contents); |
| 469 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | 284 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); |
| 470 if (!app_icon.IsEmpty()) | 285 if (!app_icon.IsEmpty()) |
| 471 return *app_icon.ToImageSkia(); | 286 return *app_icon.ToImageSkia(); |
| 472 } | 287 } |
| 473 return gfx::ImageSkia(); | 288 return gfx::ImageSkia(); |
| 474 } | 289 } |
| 475 | 290 |
| 476 views::NonClientFrameView* ChromeNativeAppWindowViews::CreateNonClientFrameView( | 291 views::NonClientFrameView* ChromeNativeAppWindowViews::CreateNonClientFrameView( |
| 477 views::Widget* widget) { | 292 views::Widget* widget) { |
| 478 #if defined(USE_ASH) | |
| 479 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | |
| 480 // Set the delegate now because CustomFrameViewAsh sets the | |
| 481 // WindowStateDelegate if one is not already set. | |
| 482 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | |
| 483 scoped_ptr<ash::wm::WindowStateDelegate>( | |
| 484 new NativeAppWindowStateDelegate(app_window(), this)).Pass()); | |
| 485 | |
| 486 if (IsFrameless()) | |
| 487 return CreateNonStandardAppFrame(); | |
| 488 | |
| 489 if (app_window()->window_type_is_panel()) { | |
| 490 views::NonClientFrameView* frame_view = | |
| 491 new ash::PanelFrameView(widget, ash::PanelFrameView::FRAME_ASH); | |
| 492 frame_view->set_context_menu_controller(this); | |
| 493 return frame_view; | |
| 494 } | |
| 495 | |
| 496 ash::CustomFrameViewAsh* custom_frame_view = | |
| 497 new ash::CustomFrameViewAsh(widget); | |
| 498 // Non-frameless app windows can be put into immersive fullscreen. | |
| 499 immersive_fullscreen_controller_.reset( | |
| 500 new ash::ImmersiveFullscreenController()); | |
| 501 custom_frame_view->InitImmersiveFullscreenControllerForView( | |
| 502 immersive_fullscreen_controller_.get()); | |
| 503 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | |
| 504 | |
| 505 if (has_frame_color_) { | |
| 506 custom_frame_view->SetFrameColors(active_frame_color_, | |
| 507 inactive_frame_color_); | |
| 508 } | |
| 509 | |
| 510 return custom_frame_view; | |
| 511 } | |
| 512 #endif | |
| 513 return (IsFrameless() || has_frame_color_) ? | 293 return (IsFrameless() || has_frame_color_) ? |
| 514 CreateNonStandardAppFrame() : CreateStandardDesktopAppFrame(); | 294 CreateNonStandardAppFrame() : CreateStandardDesktopAppFrame(); |
| 515 } | 295 } |
| 516 | 296 |
| 517 bool ChromeNativeAppWindowViews::WidgetHasHitTestMask() const { | 297 bool ChromeNativeAppWindowViews::WidgetHasHitTestMask() const { |
| 518 return shape_ != NULL; | 298 return shape_ != NULL; |
| 519 } | 299 } |
| 520 | 300 |
| 521 void ChromeNativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 301 void ChromeNativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 522 shape_->getBoundaryPath(mask); | 302 shape_->getBoundaryPath(mask); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 | 342 |
| 563 // NativeAppWindow implementation. | 343 // NativeAppWindow implementation. |
| 564 | 344 |
| 565 void ChromeNativeAppWindowViews::SetFullscreen(int fullscreen_types) { | 345 void ChromeNativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| 566 // Fullscreen not supported by panels. | 346 // Fullscreen not supported by panels. |
| 567 if (app_window()->window_type_is_panel()) | 347 if (app_window()->window_type_is_panel()) |
| 568 return; | 348 return; |
| 569 is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | 349 is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
| 570 widget()->SetFullscreen(is_fullscreen_); | 350 widget()->SetFullscreen(is_fullscreen_); |
| 571 | 351 |
| 572 #if defined(USE_ASH) | |
| 573 if (immersive_fullscreen_controller_.get()) { | |
| 574 // |immersive_fullscreen_controller_| should only be set if immersive | |
| 575 // fullscreen is the fullscreen type used by the OS. | |
| 576 immersive_fullscreen_controller_->SetEnabled( | |
| 577 ash::ImmersiveFullscreenController::WINDOW_TYPE_PACKAGED_APP, | |
| 578 (fullscreen_types & AppWindow::FULLSCREEN_TYPE_OS) != 0); | |
| 579 // Autohide the shelf instead of hiding the shelf completely when only in | |
| 580 // OS fullscreen. | |
| 581 ash::wm::WindowState* window_state = | |
| 582 ash::wm::GetWindowState(widget()->GetNativeWindow()); | |
| 583 window_state->set_hide_shelf_when_fullscreen(fullscreen_types != | |
| 584 AppWindow::FULLSCREEN_TYPE_OS); | |
| 585 DCHECK(ash::Shell::HasInstance()); | |
| 586 ash::Shell::GetInstance()->UpdateShelfVisibility(); | |
| 587 } | |
| 588 #endif | |
| 589 | |
| 590 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 352 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 591 // ever drop the window out of fullscreen in response to something that | 353 // ever drop the window out of fullscreen in response to something that |
| 592 // wasn't the app calling webkitCancelFullScreen(). | 354 // wasn't the app calling webkitCancelFullScreen(). |
| 593 } | 355 } |
| 594 | 356 |
| 595 bool ChromeNativeAppWindowViews::IsFullscreenOrPending() const { | 357 bool ChromeNativeAppWindowViews::IsFullscreenOrPending() const { |
| 596 return is_fullscreen_; | 358 return is_fullscreen_; |
| 597 } | 359 } |
| 598 | 360 |
| 599 void ChromeNativeAppWindowViews::UpdateBadgeIcon() { | 361 void ChromeNativeAppWindowViews::UpdateBadgeIcon() { |
| 600 const gfx::Image* icon = NULL; | 362 const gfx::Image* icon = NULL; |
| 601 if (!app_window()->badge_icon().IsEmpty()) { | 363 if (!app_window()->badge_icon().IsEmpty()) { |
| 602 icon = &app_window()->badge_icon(); | 364 icon = &app_window()->badge_icon(); |
| 603 // chrome::DrawTaskbarDecoration can do interesting things with non-square | 365 // chrome::DrawTaskbarDecoration can do interesting things with non-square |
| 604 // bitmaps. | 366 // bitmaps. |
| 605 // TODO(benwells): Refactor chrome::DrawTaskbarDecoration to not be avatar | 367 // TODO(benwells): Refactor chrome::DrawTaskbarDecoration to not be avatar |
| 606 // specific, and lift this restriction. | 368 // specific, and lift this restriction. |
| 607 if (icon->Width() != icon->Height()) { | 369 if (icon->Width() != icon->Height()) { |
| 608 LOG(ERROR) << "Attempt to set a non-square badge; request ignored."; | 370 LOG(ERROR) << "Attempt to set a non-square badge; request ignored."; |
| 609 return; | 371 return; |
| 610 } | 372 } |
| 611 } | 373 } |
| 612 chrome::DrawTaskbarDecoration(GetNativeWindow(), icon); | 374 chrome::DrawTaskbarDecoration(GetNativeWindow(), icon); |
| 613 } | 375 } |
| 614 | 376 |
| 615 void ChromeNativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { | 377 void ChromeNativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { |
| 616 bool had_shape = shape_; | |
| 617 shape_ = region.Pass(); | 378 shape_ = region.Pass(); |
| 618 | |
| 619 aura::Window* native_window = widget()->GetNativeWindow(); | |
| 620 if (shape_) { | |
| 621 widget()->SetShape(new SkRegion(*shape_)); | |
| 622 if (!had_shape) { | |
| 623 native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | |
| 624 new ShapedAppWindowTargeter(native_window, this))); | |
| 625 } | |
| 626 } else { | |
| 627 widget()->SetShape(NULL); | |
| 628 if (had_shape) | |
| 629 native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); | |
| 630 } | |
| 631 widget()->OnSizeConstraintsChanged(); | 379 widget()->OnSizeConstraintsChanged(); |
| 632 } | 380 } |
| 633 | 381 |
| 634 bool ChromeNativeAppWindowViews::HasFrameColor() const { | 382 bool ChromeNativeAppWindowViews::HasFrameColor() const { |
| 635 return has_frame_color_; | 383 return has_frame_color_; |
| 636 } | 384 } |
| 637 | 385 |
| 638 SkColor ChromeNativeAppWindowViews::ActiveFrameColor() const { | 386 SkColor ChromeNativeAppWindowViews::ActiveFrameColor() const { |
| 639 return active_frame_color_; | 387 return active_frame_color_; |
| 640 } | 388 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 665 InitializePanelWindow(create_params); | 413 InitializePanelWindow(create_params); |
| 666 } else { | 414 } else { |
| 667 InitializeDefaultWindow(create_params); | 415 InitializeDefaultWindow(create_params); |
| 668 } | 416 } |
| 669 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 417 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 670 Profile::FromBrowserContext(app_window->browser_context()), | 418 Profile::FromBrowserContext(app_window->browser_context()), |
| 671 widget()->GetFocusManager(), | 419 widget()->GetFocusManager(), |
| 672 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 420 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| 673 NULL)); | 421 NULL)); |
| 674 } | 422 } |
| 675 | |
| 676 apps::AppWindowFrameView* | |
| 677 ChromeNativeAppWindowViews::CreateNonStandardAppFrame() { | |
| 678 apps::AppWindowFrameView* frame = | |
| 679 new apps::AppWindowFrameView(widget(), | |
| 680 this, | |
| 681 has_frame_color_, | |
| 682 active_frame_color_, | |
| 683 inactive_frame_color_); | |
| 684 frame->Init(); | |
| 685 #if defined(USE_ASH) | |
| 686 // For Aura windows on the Ash desktop the sizes are different and the user | |
| 687 // can resize the window from slightly outside the bounds as well. | |
| 688 if (chrome::IsNativeWindowInAsh(widget()->GetNativeWindow())) { | |
| 689 frame->SetResizeSizes(ash::kResizeInsideBoundsSize, | |
| 690 ash::kResizeOutsideBoundsSize, | |
| 691 ash::kResizeAreaCornerSize); | |
| 692 } | |
| 693 #endif | |
| 694 | |
| 695 #if !defined(OS_CHROMEOS) | |
| 696 // For non-Ash windows, install an easy resize window targeter, which ensures | |
| 697 // that the root window (not the app) receives mouse events on the edges. | |
| 698 if (chrome::GetHostDesktopTypeForNativeWindow(widget()->GetNativeWindow()) != | |
| 699 chrome::HOST_DESKTOP_TYPE_ASH) { | |
| 700 aura::Window* window = widget()->GetNativeWindow(); | |
| 701 int resize_inside = frame->resize_inside_bounds_size(); | |
| 702 gfx::Insets inset( | |
| 703 resize_inside, resize_inside, resize_inside, resize_inside); | |
| 704 // Add the EasyResizeWindowTargeter on the window, not its root window. The | |
| 705 // root window does not have a delegate, which is needed to handle the event | |
| 706 // in Linux. | |
| 707 window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | |
| 708 new wm::EasyResizeWindowTargeter(window, inset, inset))); | |
| 709 } | |
| 710 #endif | |
| 711 | |
| 712 return frame; | |
| 713 } | |
| OLD | NEW |