| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" | 5 #include "apps/ui/views/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "apps/ui/views/app_window_frame_view.h" | 8 #include "apps/ui/views/shaped_app_window_targeter.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | |
| 12 #include "chrome/browser/app_mode/app_mode_utils.h" | |
| 13 #include "chrome/browser/chrome_page_zoom.h" | |
| 14 #include "chrome/browser/extensions/extension_host.h" | |
| 15 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
| 16 #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" | |
| 21 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | |
| 22 #include "chrome/browser/web_applications/web_app.h" | |
| 23 #include "chrome/common/chrome_switches.h" | |
| 24 #include "content/public/browser/browser_thread.h" | |
| 25 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 29 #include "extensions/common/draggable_region.h" | 14 #include "extensions/common/draggable_region.h" |
| 30 #include "extensions/common/extension.h" | 15 #include "third_party/skia/include/core/SkRegion.h" |
| 31 #include "ui/base/hit_test.h" | 16 #include "ui/gfx/path.h" |
| 32 #include "ui/base/models/simple_menu_model.h" | |
| 33 #include "ui/views/controls/menu/menu_runner.h" | |
| 34 #include "ui/views/controls/webview/webview.h" | 17 #include "ui/views/controls/webview/webview.h" |
| 35 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 36 #include "ui/views/window/non_client_view.h" | 19 #include "ui/views/window/non_client_view.h" |
| 37 | 20 |
| 38 #if defined(OS_LINUX) | |
| 39 #include "chrome/browser/shell_integration_linux.h" | |
| 40 #endif | |
| 41 | |
| 42 #if defined(USE_ASH) | |
| 43 #include "ash/ash_constants.h" | |
| 44 #include "ash/ash_switches.h" | |
| 45 #include "ash/screen_util.h" | |
| 46 #include "ash/shell.h" | |
| 47 #include "ash/wm/custom_frame_view_ash.h" | |
| 48 #include "ash/wm/immersive_fullscreen_controller.h" | |
| 49 #include "ash/wm/panels/panel_frame_view.h" | |
| 50 #include "ash/wm/window_state.h" | |
| 51 #include "ash/wm/window_state_delegate.h" | |
| 52 #include "ash/wm/window_state_observer.h" | |
| 53 #include "chrome/browser/ui/ash/ash_util.h" | |
| 54 #include "ui/aura/client/aura_constants.h" | |
| 55 #include "ui/aura/client/window_tree_client.h" | |
| 56 #include "ui/aura/window.h" | |
| 57 #include "ui/aura/window_observer.h" | |
| 58 #endif | |
| 59 | |
| 60 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
| 61 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 62 #endif | 23 #endif |
| 63 | 24 |
| 64 using apps::AppWindow; | 25 using apps::AppWindow; |
| 65 | 26 |
| 66 namespace { | |
| 67 | |
| 68 const int kMinPanelWidth = 100; | |
| 69 const int kMinPanelHeight = 100; | |
| 70 const int kDefaultPanelWidth = 200; | |
| 71 const int kDefaultPanelHeight = 300; | |
| 72 const int kResizeInsideBoundsSize = 5; | |
| 73 const int kResizeAreaCornerSize = 16; | |
| 74 | |
| 75 struct AcceleratorMapping { | |
| 76 ui::KeyboardCode keycode; | |
| 77 int modifiers; | |
| 78 int command_id; | |
| 79 }; | |
| 80 | |
| 81 const AcceleratorMapping kAppWindowAcceleratorMap[] = { | |
| 82 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | |
| 83 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | |
| 84 { ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW }, | |
| 85 }; | |
| 86 | |
| 87 // These accelerators will only be available in kiosk mode. These allow the | |
| 88 // user to manually zoom app windows. This is only necessary in kiosk mode | |
| 89 // (in normal mode, the user can zoom via the screen magnifier). | |
| 90 // TODO(xiyuan): Write a test for kiosk accelerators. | |
| 91 const AcceleratorMapping kAppWindowKioskAppModeAcceleratorMap[] = { | |
| 92 { ui::VKEY_OEM_MINUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, | |
| 93 { ui::VKEY_OEM_MINUS, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, | |
| 94 IDC_ZOOM_MINUS }, | |
| 95 { ui::VKEY_SUBTRACT, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, | |
| 96 { ui::VKEY_OEM_PLUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
| 97 { ui::VKEY_OEM_PLUS, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
| 98 { ui::VKEY_ADD, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
| 99 { ui::VKEY_0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, | |
| 100 { ui::VKEY_NUMPAD0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, | |
| 101 }; | |
| 102 | |
| 103 void AddAcceleratorsFromMapping(const AcceleratorMapping mapping[], | |
| 104 size_t mapping_length, | |
| 105 std::map<ui::Accelerator, int>* accelerators) { | |
| 106 for (size_t i = 0; i < mapping_length; ++i) { | |
| 107 ui::Accelerator accelerator(mapping[i].keycode, mapping[i].modifiers); | |
| 108 (*accelerators)[accelerator] = mapping[i].command_id; | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 const std::map<ui::Accelerator, int>& GetAcceleratorTable() { | |
| 113 typedef std::map<ui::Accelerator, int> AcceleratorMap; | |
| 114 CR_DEFINE_STATIC_LOCAL(AcceleratorMap, accelerators, ()); | |
| 115 if (accelerators.empty()) { | |
| 116 AddAcceleratorsFromMapping( | |
| 117 kAppWindowAcceleratorMap, | |
| 118 arraysize(kAppWindowAcceleratorMap), | |
| 119 &accelerators); | |
| 120 | |
| 121 // Add accelerators for kiosk mode. | |
| 122 if (chrome::IsRunningInForcedAppMode()) { | |
| 123 AddAcceleratorsFromMapping( | |
| 124 kAppWindowKioskAppModeAcceleratorMap, | |
| 125 arraysize(kAppWindowKioskAppModeAcceleratorMap), | |
| 126 &accelerators); | |
| 127 } | |
| 128 } | |
| 129 return accelerators; | |
| 130 } | |
| 131 | |
| 132 #if defined(USE_ASH) | |
| 133 // This class handles a user's fullscreen request (Shift+F4/F4). | |
| 134 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, | |
| 135 public ash::wm::WindowStateObserver, | |
| 136 public aura::WindowObserver { | |
| 137 public: | |
| 138 NativeAppWindowStateDelegate(AppWindow* app_window, | |
| 139 apps::NativeAppWindow* native_app_window) | |
| 140 : app_window_(app_window), | |
| 141 window_state_( | |
| 142 ash::wm::GetWindowState(native_app_window->GetNativeWindow())) { | |
| 143 // Add a window state observer to exit fullscreen properly in case | |
| 144 // fullscreen is exited without going through AppWindow::Restore(). This | |
| 145 // is the case when exiting immersive fullscreen via the "Restore" window | |
| 146 // control. | |
| 147 // TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048 | |
| 148 window_state_->AddObserver(this); | |
| 149 window_state_->window()->AddObserver(this); | |
| 150 } | |
| 151 virtual ~NativeAppWindowStateDelegate(){ | |
| 152 if (window_state_) { | |
| 153 window_state_->RemoveObserver(this); | |
| 154 window_state_->window()->RemoveObserver(this); | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 private: | |
| 159 // Overridden from ash::wm::WindowStateDelegate. | |
| 160 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { | |
| 161 // Windows which cannot be maximized should not be fullscreened. | |
| 162 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); | |
| 163 if (window_state->IsFullscreen()) | |
| 164 app_window_->Restore(); | |
| 165 else if (window_state->CanMaximize()) | |
| 166 app_window_->OSFullscreen(); | |
| 167 return true; | |
| 168 } | |
| 169 | |
| 170 // Overridden from ash::wm::WindowStateObserver: | |
| 171 virtual void OnPostWindowShowTypeChange( | |
| 172 ash::wm::WindowState* window_state, | |
| 173 ash::wm::WindowShowType old_type) OVERRIDE { | |
| 174 if (!window_state->IsFullscreen() && !window_state->IsMinimized() && | |
| 175 app_window_->GetBaseWindow()->IsFullscreenOrPending()) { | |
| 176 app_window_->Restore(); | |
| 177 // Usually OnNativeWindowChanged() is called when the window bounds are | |
| 178 // changed as a result of a show type change. Because the change in show | |
| 179 // type has already occurred, we need to call OnNativeWindowChanged() | |
| 180 // explicitly. | |
| 181 app_window_->OnNativeWindowChanged(); | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 // Overridden from aura::WindowObserver: | |
| 186 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | |
| 187 window_state_->RemoveObserver(this); | |
| 188 window_state_->window()->RemoveObserver(this); | |
| 189 window_state_ = NULL; | |
| 190 } | |
| 191 | |
| 192 // Not owned. | |
| 193 AppWindow* app_window_; | |
| 194 ash::wm::WindowState* window_state_; | |
| 195 | |
| 196 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | |
| 197 }; | |
| 198 #endif // USE_ASH | |
| 199 | |
| 200 } // namespace | |
| 201 | |
| 202 NativeAppWindowViews::NativeAppWindowViews() | 27 NativeAppWindowViews::NativeAppWindowViews() |
| 203 : web_view_(NULL), | 28 : app_window_(NULL), |
| 29 web_view_(NULL), |
| 204 window_(NULL), | 30 window_(NULL), |
| 205 is_fullscreen_(false), | 31 frameless_(false), |
| 206 weak_ptr_factory_(this) { | 32 transparent_background_(false), |
| 207 } | 33 resizable_(false) {} |
| 208 | 34 |
| 209 void NativeAppWindowViews::Init(apps::AppWindow* app_window, | 35 void NativeAppWindowViews::Init(apps::AppWindow* app_window, |
| 210 const AppWindow::CreateParams& create_params) { | 36 const AppWindow::CreateParams& create_params) { |
| 211 app_window_ = app_window; | 37 app_window_ = app_window; |
| 212 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 38 frameless_ = create_params.frame == AppWindow::FRAME_NONE; |
| 213 transparent_background_ = create_params.transparent_background; | 39 transparent_background_ = create_params.transparent_background; |
| 214 resizable_ = create_params.resizable; | 40 resizable_ = create_params.resizable; |
| 215 Observe(web_contents()); | 41 Observe(app_window_->web_contents()); |
| 216 | 42 |
| 217 window_ = new views::Widget; | 43 window_ = new views::Widget; |
| 218 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || | 44 InitializeWindow(app_window, create_params); |
| 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 | 45 |
| 230 OnViewWasResized(); | 46 OnViewWasResized(); |
| 231 window_->AddObserver(this); | 47 window_->AddObserver(this); |
| 232 } | 48 } |
| 233 | 49 |
| 234 NativeAppWindowViews::~NativeAppWindowViews() { | 50 NativeAppWindowViews::~NativeAppWindowViews() { |
| 235 web_view_->SetWebContents(NULL); | 51 web_view_->SetWebContents(NULL); |
| 236 } | 52 } |
| 237 | 53 |
| 238 void NativeAppWindowViews::OnBeforeWidgetInit( | 54 void NativeAppWindowViews::InitializeWindow( |
| 239 views::Widget::InitParams* init_params, | 55 apps::AppWindow* app_window, |
| 240 views::Widget* widget) {} | 56 const apps::AppWindow::CreateParams& create_params) { |
| 241 | 57 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 242 void NativeAppWindowViews::InitializeDefaultWindow( | |
| 243 const AppWindow::CreateParams& create_params) { | |
| 244 std::string app_name = | |
| 245 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); | |
| 246 | |
| 247 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 58 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 248 init_params.delegate = this; | 59 init_params.delegate = this; |
| 249 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); | |
| 250 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 251 // On Linux, remove the standard frame. Instead, we will use CustomFrameView | |
| 252 // to draw a native-like frame. | |
| 253 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. | |
| 254 init_params.remove_standard_frame = true; | |
| 255 #endif | |
| 256 init_params.use_system_default_icon = true; | |
| 257 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | |
| 258 // could plumb context through to here in some cases. | |
| 259 init_params.top_level = true; | 60 init_params.top_level = true; |
| 260 if (create_params.transparent_background) | |
| 261 init_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 262 init_params.keep_on_top = create_params.always_on_top; | 61 init_params.keep_on_top = create_params.always_on_top; |
| 263 gfx::Rect window_bounds = create_params.bounds; | |
| 264 bool position_specified = | |
| 265 window_bounds.x() != INT_MIN && window_bounds.y() != INT_MIN; | |
| 266 if (position_specified && !window_bounds.IsEmpty()) | |
| 267 init_params.bounds = window_bounds; | |
| 268 | |
| 269 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 270 // Set up a custom WM_CLASS for app windows. This allows task switchers in | |
| 271 // X11 environments to distinguish them from main browser windows. | |
| 272 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); | |
| 273 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); | |
| 274 const char kX11WindowRoleApp[] = "app"; | |
| 275 init_params.wm_role_name = std::string(kX11WindowRoleApp); | |
| 276 #endif | |
| 277 | |
| 278 OnBeforeWidgetInit(&init_params, window_); | |
| 279 window_->Init(init_params); | 62 window_->Init(init_params); |
| 280 | 63 window_->CenterWindow(create_params.bounds.size()); |
| 281 gfx::Rect adjusted_bounds = window_bounds; | |
| 282 adjusted_bounds.Inset(-GetFrameInsets()); | |
| 283 // Center window if no position was specified. | |
| 284 if (!position_specified) | |
| 285 window_->CenterWindow(adjusted_bounds.size()); | |
| 286 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) | |
| 287 window_->SetBounds(adjusted_bounds); | |
| 288 | |
| 289 // Register accelarators supported by app windows. | |
| 290 // TODO(jeremya/stevenjb): should these be registered for panels too? | |
| 291 views::FocusManager* focus_manager = GetFocusManager(); | |
| 292 const std::map<ui::Accelerator, int>& accelerator_table = | |
| 293 GetAcceleratorTable(); | |
| 294 const bool is_kiosk_app_mode = chrome::IsRunningInForcedAppMode(); | |
| 295 | |
| 296 // Ensures that kiosk mode accelerators are enabled when in kiosk mode (to be | |
| 297 // 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 | |
| 299 // launched before kiosk mode starts, the kiosk accelerators will not be | |
| 300 // registered. This DCHECK catches the case. | |
| 301 DCHECK(!is_kiosk_app_mode || | |
| 302 accelerator_table.size() == | |
| 303 arraysize(kAppWindowAcceleratorMap) + | |
| 304 arraysize(kAppWindowKioskAppModeAcceleratorMap)); | |
| 305 | |
| 306 for (std::map<ui::Accelerator, int>::const_iterator iter = | |
| 307 accelerator_table.begin(); | |
| 308 iter != accelerator_table.end(); ++iter) { | |
| 309 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) | |
| 310 continue; | |
| 311 | |
| 312 focus_manager->RegisterAccelerator( | |
| 313 iter->first, ui::AcceleratorManager::kNormalPriority, this); | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 void NativeAppWindowViews::InitializePanelWindow( | |
| 318 const AppWindow::CreateParams& create_params) { | |
| 319 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | |
| 320 params.delegate = this; | |
| 321 | |
| 322 preferred_size_ = gfx::Size(create_params.bounds.width(), | |
| 323 create_params.bounds.height()); | |
| 324 if (preferred_size_.width() == 0) | |
| 325 preferred_size_.set_width(kDefaultPanelWidth); | |
| 326 else if (preferred_size_.width() < kMinPanelWidth) | |
| 327 preferred_size_.set_width(kMinPanelWidth); | |
| 328 | |
| 329 if (preferred_size_.height() == 0) | |
| 330 preferred_size_.set_height(kDefaultPanelHeight); | |
| 331 else if (preferred_size_.height() < kMinPanelHeight) | |
| 332 preferred_size_.set_height(kMinPanelHeight); | |
| 333 #if defined(USE_ASH) | |
| 334 if (ash::Shell::HasInstance()) { | |
| 335 // Open a new panel on the target root. | |
| 336 aura::Window* target = ash::Shell::GetTargetRootWindow(); | |
| 337 params.bounds = ash::ScreenUtil::ConvertRectToScreen( | |
| 338 target, gfx::Rect(preferred_size_)); | |
| 339 } else { | |
| 340 params.bounds = gfx::Rect(preferred_size_); | |
| 341 } | |
| 342 #else | |
| 343 params.bounds = gfx::Rect(preferred_size_); | |
| 344 #endif | |
| 345 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | |
| 346 // could plumb context through to here in some cases. | |
| 347 params.top_level = true; | |
| 348 window_->Init(params); | |
| 349 window_->set_focus_on_creation(create_params.focused); | |
| 350 | |
| 351 #if defined(USE_ASH) | |
| 352 if (create_params.state == ui::SHOW_STATE_DETACHED) { | |
| 353 gfx::Rect window_bounds(create_params.bounds.x(), | |
| 354 create_params.bounds.y(), | |
| 355 preferred_size_.width(), | |
| 356 preferred_size_.height()); | |
| 357 aura::Window* native_window = GetNativeWindow(); | |
| 358 ash::wm::GetWindowState(native_window)->set_panel_attached(false); | |
| 359 aura::client::ParentWindowWithContext(native_window, | |
| 360 native_window->GetRootWindow(), | |
| 361 native_window->GetBoundsInScreen()); | |
| 362 window_->SetBounds(window_bounds); | |
| 363 } | |
| 364 #else | |
| 365 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | |
| 366 // platforms. | |
| 367 #endif | |
| 368 } | |
| 369 | |
| 370 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { | |
| 371 if (frameless_) | |
| 372 return true; | |
| 373 | |
| 374 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 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 } | 64 } |
| 407 | 65 |
| 408 // ui::BaseWindow implementation. | 66 // ui::BaseWindow implementation. |
| 409 | 67 |
| 410 bool NativeAppWindowViews::IsActive() const { | 68 bool NativeAppWindowViews::IsActive() const { |
| 411 return window_->IsActive(); | 69 return window_->IsActive(); |
| 412 } | 70 } |
| 413 | 71 |
| 414 bool NativeAppWindowViews::IsMaximized() const { | 72 bool NativeAppWindowViews::IsMaximized() const { |
| 415 return window_->IsMaximized(); | 73 return window_->IsMaximized(); |
| 416 } | 74 } |
| 417 | 75 |
| 418 bool NativeAppWindowViews::IsMinimized() const { | 76 bool NativeAppWindowViews::IsMinimized() const { |
| 419 return window_->IsMinimized(); | 77 return window_->IsMinimized(); |
| 420 } | 78 } |
| 421 | 79 |
| 422 bool NativeAppWindowViews::IsFullscreen() const { | 80 bool NativeAppWindowViews::IsFullscreen() const { |
| 423 return window_->IsFullscreen(); | 81 return window_->IsFullscreen(); |
| 424 } | 82 } |
| 425 | 83 |
| 426 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { | 84 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { |
| 427 return window_->GetNativeWindow(); | 85 return window_->GetNativeWindow(); |
| 428 } | 86 } |
| 429 | 87 |
| 430 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { | 88 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { |
| 431 return window_->GetRestoredBounds(); | 89 return window_->GetRestoredBounds(); |
| 432 } | 90 } |
| 433 | 91 |
| 434 ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { | 92 ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { |
| 93 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 435 if (IsMaximized()) | 94 if (IsMaximized()) |
| 436 return ui::SHOW_STATE_MAXIMIZED; | 95 return ui::SHOW_STATE_MAXIMIZED; |
| 437 if (IsFullscreen()) { | 96 if (IsFullscreen()) |
| 438 #if defined(USE_ASH) | |
| 439 if (immersive_fullscreen_controller_.get() && | |
| 440 immersive_fullscreen_controller_->IsEnabled()) { | |
| 441 // Restore windows which were previously in immersive fullscreen to | |
| 442 // maximized. Restoring the window to a different fullscreen type | |
| 443 // makes for a bad experience. | |
| 444 return ui::SHOW_STATE_MAXIMIZED; | |
| 445 } | |
| 446 #endif | |
| 447 return ui::SHOW_STATE_FULLSCREEN; | 97 return ui::SHOW_STATE_FULLSCREEN; |
| 448 } | |
| 449 #if defined(USE_ASH) | |
| 450 // Use kRestoreShowStateKey in case a window is minimized/hidden. | |
| 451 ui::WindowShowState restore_state = | |
| 452 window_->GetNativeWindow()->GetProperty( | |
| 453 aura::client::kRestoreShowStateKey); | |
| 454 // Whitelist states to return so that invalid and transient states | |
| 455 // are not saved and used to restore windows when they are recreated. | |
| 456 switch (restore_state) { | |
| 457 case ui::SHOW_STATE_NORMAL: | |
| 458 case ui::SHOW_STATE_MAXIMIZED: | |
| 459 case ui::SHOW_STATE_FULLSCREEN: | |
| 460 case ui::SHOW_STATE_DETACHED: | |
| 461 return restore_state; | |
| 462 | |
| 463 case ui::SHOW_STATE_DEFAULT: | |
| 464 case ui::SHOW_STATE_MINIMIZED: | |
| 465 case ui::SHOW_STATE_INACTIVE: | |
| 466 case ui::SHOW_STATE_END: | |
| 467 return ui::SHOW_STATE_NORMAL; | |
| 468 } | |
| 469 #endif | |
| 470 return ui::SHOW_STATE_NORMAL; | 98 return ui::SHOW_STATE_NORMAL; |
| 471 } | 99 } |
| 472 | 100 |
| 473 gfx::Rect NativeAppWindowViews::GetBounds() const { | 101 gfx::Rect NativeAppWindowViews::GetBounds() const { |
| 474 return window_->GetWindowBoundsInScreen(); | 102 return window_->GetWindowBoundsInScreen(); |
| 475 } | 103 } |
| 476 | 104 |
| 477 void NativeAppWindowViews::Show() { | 105 void NativeAppWindowViews::Show() { |
| 478 if (window_->IsVisible()) { | 106 if (window_->IsVisible()) { |
| 479 window_->Activate(); | 107 window_->Activate(); |
| 480 return; | 108 return; |
| 481 } | 109 } |
| 482 | |
| 483 window_->Show(); | 110 window_->Show(); |
| 484 } | 111 } |
| 485 | 112 |
| 486 void NativeAppWindowViews::ShowInactive() { | 113 void NativeAppWindowViews::ShowInactive() { |
| 487 if (window_->IsVisible()) | 114 if (window_->IsVisible()) |
| 488 return; | 115 return; |
| 116 |
| 489 window_->ShowInactive(); | 117 window_->ShowInactive(); |
| 490 } | 118 } |
| 491 | 119 |
| 492 void NativeAppWindowViews::Hide() { | 120 void NativeAppWindowViews::Hide() { |
| 493 window_->Hide(); | 121 window_->Hide(); |
| 494 } | 122 } |
| 495 | 123 |
| 496 void NativeAppWindowViews::Close() { | 124 void NativeAppWindowViews::Close() { |
| 497 window_->Close(); | 125 window_->Close(); |
| 498 } | 126 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 519 | 147 |
| 520 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { | 148 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { |
| 521 window_->SetBounds(bounds); | 149 window_->SetBounds(bounds); |
| 522 } | 150 } |
| 523 | 151 |
| 524 void NativeAppWindowViews::FlashFrame(bool flash) { | 152 void NativeAppWindowViews::FlashFrame(bool flash) { |
| 525 window_->FlashFrame(flash); | 153 window_->FlashFrame(flash); |
| 526 } | 154 } |
| 527 | 155 |
| 528 bool NativeAppWindowViews::IsAlwaysOnTop() const { | 156 bool NativeAppWindowViews::IsAlwaysOnTop() const { |
| 529 if (app_window_->window_type_is_panel()) { | 157 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 530 #if defined(USE_ASH) | 158 return window_->IsAlwaysOnTop(); |
| 531 return ash::wm::GetWindowState(window_->GetNativeWindow())-> | |
| 532 panel_attached(); | |
| 533 #else | |
| 534 return true; | |
| 535 #endif | |
| 536 } else { | |
| 537 return window_->IsAlwaysOnTop(); | |
| 538 } | |
| 539 } | 159 } |
| 540 | 160 |
| 541 void NativeAppWindowViews::SetAlwaysOnTop(bool always_on_top) { | 161 void NativeAppWindowViews::SetAlwaysOnTop(bool always_on_top) { |
| 542 window_->SetAlwaysOnTop(always_on_top); | 162 window_->SetAlwaysOnTop(always_on_top); |
| 543 } | 163 } |
| 544 | 164 |
| 545 void NativeAppWindowViews::ShowContextMenuForView( | |
| 546 views::View* source, | |
| 547 const gfx::Point& p, | |
| 548 ui::MenuSourceType source_type) { | |
| 549 #if defined(USE_ASH) & defined(OS_CHROMEOS) | |
| 550 scoped_ptr<ui::MenuModel> model = | |
| 551 CreateMultiUserContextMenu(app_window_->GetNativeWindow()); | |
| 552 if (!model.get()) | |
| 553 return; | |
| 554 | |
| 555 // Only show context menu if point is in caption. | |
| 556 gfx::Point point_in_view_coords(p); | |
| 557 views::View::ConvertPointFromScreen(window_->non_client_view(), | |
| 558 &point_in_view_coords); | |
| 559 int hit_test = window_->non_client_view()->NonClientHitTest( | |
| 560 point_in_view_coords); | |
| 561 if (hit_test == HTCAPTION) { | |
| 562 menu_runner_.reset(new views::MenuRunner(model.get())); | |
| 563 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL, | |
| 564 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT, | |
| 565 source_type, | |
| 566 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | |
| 567 views::MenuRunner::MENU_DELETED) | |
| 568 return; | |
| 569 } | |
| 570 #endif | |
| 571 } | |
| 572 | |
| 573 gfx::NativeView NativeAppWindowViews::GetHostView() const { | 165 gfx::NativeView NativeAppWindowViews::GetHostView() const { |
| 574 return window_->GetNativeView(); | 166 return window_->GetNativeView(); |
| 575 } | 167 } |
| 576 | 168 |
| 577 gfx::Point NativeAppWindowViews::GetDialogPosition(const gfx::Size& size) { | 169 gfx::Point NativeAppWindowViews::GetDialogPosition(const gfx::Size& size) { |
| 578 gfx::Size app_window_size = window_->GetWindowBoundsInScreen().size(); | 170 gfx::Size app_window_size = window_->GetWindowBoundsInScreen().size(); |
| 579 return gfx::Point(app_window_size.width() / 2 - size.width() / 2, | 171 return gfx::Point(app_window_size.width() / 2 - size.width() / 2, |
| 580 app_window_size.height() / 2 - size.height() / 2); | 172 app_window_size.height() / 2 - size.height() / 2); |
| 581 } | 173 } |
| 582 | 174 |
| 583 gfx::Size NativeAppWindowViews::GetMaximumDialogSize() { | 175 gfx::Size NativeAppWindowViews::GetMaximumDialogSize() { |
| 584 return window_->GetWindowBoundsInScreen().size(); | 176 return window_->GetWindowBoundsInScreen().size(); |
| 585 } | 177 } |
| 586 | 178 |
| 587 void NativeAppWindowViews::AddObserver( | 179 void NativeAppWindowViews::AddObserver( |
| 588 web_modal::ModalDialogHostObserver* observer) { | 180 web_modal::ModalDialogHostObserver* observer) { |
| 589 observer_list_.AddObserver(observer); | 181 observer_list_.AddObserver(observer); |
| 590 } | 182 } |
| 591 void NativeAppWindowViews::RemoveObserver( | 183 void NativeAppWindowViews::RemoveObserver( |
| 592 web_modal::ModalDialogHostObserver* observer) { | 184 web_modal::ModalDialogHostObserver* observer) { |
| 593 observer_list_.RemoveObserver(observer); | 185 observer_list_.RemoveObserver(observer); |
| 594 } | 186 } |
| 595 | 187 |
| 596 // Private method. TODO(stevenjb): Move this below InitializePanelWindow() | |
| 597 // to match declaration order. | |
| 598 void NativeAppWindowViews::OnViewWasResized() { | 188 void NativeAppWindowViews::OnViewWasResized() { |
| 599 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 189 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
| 600 observer_list_, | 190 observer_list_, |
| 601 OnPositionRequiresUpdate()); | 191 OnPositionRequiresUpdate()); |
| 602 } | 192 } |
| 603 | 193 |
| 604 // WidgetDelegate implementation. | 194 // WidgetDelegate implementation. |
| 605 | 195 |
| 606 void NativeAppWindowViews::OnWidgetMove() { | 196 void NativeAppWindowViews::OnWidgetMove() { |
| 607 app_window_->OnNativeWindowChanged(); | 197 app_window_->OnNativeWindowChanged(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 621 } | 211 } |
| 622 | 212 |
| 623 base::string16 NativeAppWindowViews::GetWindowTitle() const { | 213 base::string16 NativeAppWindowViews::GetWindowTitle() const { |
| 624 return app_window_->GetTitle(); | 214 return app_window_->GetTitle(); |
| 625 } | 215 } |
| 626 | 216 |
| 627 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 217 bool NativeAppWindowViews::ShouldShowWindowTitle() const { |
| 628 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 218 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; |
| 629 } | 219 } |
| 630 | 220 |
| 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) { | |
| 642 FaviconTabHelper* favicon_tab_helper = | |
| 643 FaviconTabHelper::FromWebContents(web_contents); | |
| 644 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | |
| 645 if (!app_icon.IsEmpty()) | |
| 646 return *app_icon.ToImageSkia(); | |
| 647 } | |
| 648 return gfx::ImageSkia(); | |
| 649 } | |
| 650 | |
| 651 bool NativeAppWindowViews::ShouldShowWindowIcon() const { | 221 bool NativeAppWindowViews::ShouldShowWindowIcon() const { |
| 652 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 222 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; |
| 653 } | 223 } |
| 654 | 224 |
| 655 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | 225 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, |
| 656 ui::WindowShowState show_state) { | 226 ui::WindowShowState show_state) { |
| 657 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 227 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
| 658 app_window_->OnNativeWindowChanged(); | 228 app_window_->OnNativeWindowChanged(); |
| 659 } | 229 } |
| 660 | 230 |
| 661 void NativeAppWindowViews::DeleteDelegate() { | 231 void NativeAppWindowViews::DeleteDelegate() { |
| 662 window_->RemoveObserver(this); | 232 window_->RemoveObserver(this); |
| 663 app_window_->OnNativeClose(); | 233 app_window_->OnNativeClose(); |
| 664 } | 234 } |
| 665 | 235 |
| 666 views::Widget* NativeAppWindowViews::GetWidget() { | 236 views::Widget* NativeAppWindowViews::GetWidget() { |
| 667 return window_; | 237 return window_; |
| 668 } | 238 } |
| 669 | 239 |
| 670 const views::Widget* NativeAppWindowViews::GetWidget() const { | 240 const views::Widget* NativeAppWindowViews::GetWidget() const { |
| 671 return window_; | 241 return window_; |
| 672 } | 242 } |
| 673 | 243 |
| 674 views::View* NativeAppWindowViews::GetContentsView() { | 244 views::View* NativeAppWindowViews::GetContentsView() { |
| 675 return this; | 245 return this; |
| 676 } | 246 } |
| 677 | 247 |
| 678 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | |
| 679 views::Widget* widget) { | |
| 680 #if defined(USE_ASH) | |
| 681 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | |
| 682 // Set the delegate now because CustomFrameViewAsh sets the | |
| 683 // WindowStateDelegate if one is not already set. | |
| 684 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | |
| 685 scoped_ptr<ash::wm::WindowStateDelegate>( | |
| 686 new NativeAppWindowStateDelegate(app_window_, this)).Pass()); | |
| 687 | |
| 688 if (app_window_->window_type_is_panel()) { | |
| 689 ash::PanelFrameView::FrameType frame_type = frameless_ ? | |
| 690 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | |
| 691 views::NonClientFrameView* frame_view = | |
| 692 new ash::PanelFrameView(widget, frame_type); | |
| 693 frame_view->set_context_menu_controller(this); | |
| 694 return frame_view; | |
| 695 } | |
| 696 | |
| 697 if (!frameless_) { | |
| 698 ash::CustomFrameViewAsh* custom_frame_view = | |
| 699 new ash::CustomFrameViewAsh(widget); | |
| 700 #if defined(OS_CHROMEOS) | |
| 701 // Non-frameless app windows can be put into immersive fullscreen. | |
| 702 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for | |
| 703 // Windows Ash. | |
| 704 if (ash::switches::UseImmersiveFullscreenForAllWindows()) { | |
| 705 immersive_fullscreen_controller_.reset( | |
| 706 new ash::ImmersiveFullscreenController()); | |
| 707 custom_frame_view->InitImmersiveFullscreenControllerForView( | |
| 708 immersive_fullscreen_controller_.get()); | |
| 709 } | |
| 710 #endif | |
| 711 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | |
| 712 return custom_frame_view; | |
| 713 } | |
| 714 } | |
| 715 #endif | |
| 716 if (ShouldUseChromeStyleFrame()) | |
| 717 return CreateAppWindowFrameView(); | |
| 718 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | |
| 719 } | |
| 720 | |
| 721 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 248 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 722 return shape_ != NULL; | 249 return shape_ != NULL; |
| 723 } | 250 } |
| 724 | 251 |
| 725 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 252 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 726 shape_->getBoundaryPath(mask); | 253 shape_->getBoundaryPath(mask); |
| 727 } | 254 } |
| 728 | 255 |
| 729 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( | 256 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( |
| 730 gfx::NativeView child, | 257 gfx::NativeView child, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 DCHECK(web_view_); | 311 DCHECK(web_view_); |
| 785 web_view_->SetBounds(0, 0, width(), height()); | 312 web_view_->SetBounds(0, 0, width(), height()); |
| 786 OnViewWasResized(); | 313 OnViewWasResized(); |
| 787 } | 314 } |
| 788 | 315 |
| 789 void NativeAppWindowViews::ViewHierarchyChanged( | 316 void NativeAppWindowViews::ViewHierarchyChanged( |
| 790 const ViewHierarchyChangedDetails& details) { | 317 const ViewHierarchyChangedDetails& details) { |
| 791 if (details.is_add && details.child == this) { | 318 if (details.is_add && details.child == this) { |
| 792 web_view_ = new views::WebView(NULL); | 319 web_view_ = new views::WebView(NULL); |
| 793 AddChildView(web_view_); | 320 AddChildView(web_view_); |
| 794 web_view_->SetWebContents(web_contents()); | 321 web_view_->SetWebContents(app_window_->web_contents()); |
| 795 } | 322 } |
| 796 } | 323 } |
| 797 | 324 |
| 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() { | 325 gfx::Size NativeAppWindowViews::GetMinimumSize() { |
| 805 return app_window_->size_constraints().GetMinimumSize(); | 326 return app_window_->size_constraints().GetMinimumSize(); |
| 806 } | 327 } |
| 807 | 328 |
| 808 gfx::Size NativeAppWindowViews::GetMaximumSize() { | 329 gfx::Size NativeAppWindowViews::GetMaximumSize() { |
| 809 return app_window_->size_constraints().GetMaximumSize(); | 330 return app_window_->size_constraints().GetMaximumSize(); |
| 810 } | 331 } |
| 811 | 332 |
| 812 void NativeAppWindowViews::OnFocus() { | 333 void NativeAppWindowViews::OnFocus() { |
| 813 web_view_->RequestFocus(); | 334 web_view_->RequestFocus(); |
| 814 } | 335 } |
| 815 | 336 |
| 816 bool NativeAppWindowViews::AcceleratorPressed( | |
| 817 const ui::Accelerator& accelerator) { | |
| 818 const std::map<ui::Accelerator, int>& accelerator_table = | |
| 819 GetAcceleratorTable(); | |
| 820 std::map<ui::Accelerator, int>::const_iterator iter = | |
| 821 accelerator_table.find(accelerator); | |
| 822 DCHECK(iter != accelerator_table.end()); | |
| 823 int command_id = iter->second; | |
| 824 switch (command_id) { | |
| 825 case IDC_CLOSE_WINDOW: | |
| 826 Close(); | |
| 827 return true; | |
| 828 case IDC_ZOOM_MINUS: | |
| 829 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | |
| 830 content::PAGE_ZOOM_OUT); | |
| 831 return true; | |
| 832 case IDC_ZOOM_NORMAL: | |
| 833 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | |
| 834 content::PAGE_ZOOM_RESET); | |
| 835 return true; | |
| 836 case IDC_ZOOM_PLUS: | |
| 837 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | |
| 838 content::PAGE_ZOOM_IN); | |
| 839 return true; | |
| 840 default: | |
| 841 NOTREACHED() << "Unknown accelerator sent to app window."; | |
| 842 } | |
| 843 return false; | |
| 844 } | |
| 845 | |
| 846 // NativeAppWindow implementation. | 337 // NativeAppWindow implementation. |
| 847 | 338 |
| 848 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { | 339 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| 849 // Fullscreen not supported by panels. | 340 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 850 if (app_window_->window_type_is_panel()) | 341 window_->SetFullscreen(fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
| 851 return; | |
| 852 is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | |
| 853 window_->SetFullscreen(is_fullscreen_); | |
| 854 | |
| 855 #if defined(USE_ASH) | |
| 856 if (immersive_fullscreen_controller_.get()) { | |
| 857 // |immersive_fullscreen_controller_| should only be set if immersive | |
| 858 // fullscreen is the fullscreen type used by the OS. | |
| 859 immersive_fullscreen_controller_->SetEnabled( | |
| 860 ash::ImmersiveFullscreenController::WINDOW_TYPE_PACKAGED_APP, | |
| 861 (fullscreen_types & AppWindow::FULLSCREEN_TYPE_OS) != 0); | |
| 862 // Autohide the shelf instead of hiding the shelf completely when only in | |
| 863 // OS fullscreen. | |
| 864 ash::wm::WindowState* window_state = | |
| 865 ash::wm::GetWindowState(window_->GetNativeWindow()); | |
| 866 window_state->set_hide_shelf_when_fullscreen(fullscreen_types != | |
| 867 AppWindow::FULLSCREEN_TYPE_OS); | |
| 868 DCHECK(ash::Shell::HasInstance()); | |
| 869 ash::Shell::GetInstance()->UpdateShelfVisibility(); | |
| 870 } | |
| 871 #endif | |
| 872 | |
| 873 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | |
| 874 // ever drop the window out of fullscreen in response to something that | |
| 875 // wasn't the app calling webkitCancelFullScreen(). | |
| 876 } | 342 } |
| 877 | 343 |
| 878 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 344 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
| 879 return is_fullscreen_; | 345 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 346 return window_->IsFullscreen(); |
| 880 } | 347 } |
| 881 | 348 |
| 882 bool NativeAppWindowViews::IsDetached() const { | 349 bool NativeAppWindowViews::IsDetached() const { |
| 883 if (!app_window_->window_type_is_panel()) | 350 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 884 return false; | |
| 885 #if defined(USE_ASH) | |
| 886 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); | |
| 887 #else | |
| 888 return false; | 351 return false; |
| 889 #endif | |
| 890 } | 352 } |
| 891 | 353 |
| 892 void NativeAppWindowViews::UpdateWindowIcon() { | 354 void NativeAppWindowViews::UpdateWindowIcon() { |
| 893 window_->UpdateWindowIcon(); | 355 window_->UpdateWindowIcon(); |
| 894 } | 356 } |
| 895 | 357 |
| 896 void NativeAppWindowViews::UpdateWindowTitle() { | 358 void NativeAppWindowViews::UpdateWindowTitle() { |
| 897 window_->UpdateWindowTitle(); | 359 window_->UpdateWindowTitle(); |
| 898 } | 360 } |
| 899 | 361 |
| 900 void NativeAppWindowViews::UpdateBadgeIcon() { | 362 void NativeAppWindowViews::UpdateBadgeIcon() { |
| 901 const gfx::Image* icon = NULL; | 363 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 902 if (!app_window_->badge_icon().IsEmpty()) { | |
| 903 icon = &app_window_->badge_icon(); | |
| 904 // chrome::DrawTaskbarDecoration can do interesting things with non-square | |
| 905 // bitmaps. | |
| 906 // TODO(benwells): Refactor chrome::DrawTaskbarDecoration to not be avatar | |
| 907 // specific, and lift this restriction. | |
| 908 if (icon->Width() != icon->Height()) { | |
| 909 LOG(ERROR) << "Attempt to set a non-square badge; request ignored."; | |
| 910 return; | |
| 911 } | |
| 912 } | |
| 913 chrome::DrawTaskbarDecoration(GetNativeWindow(), icon); | |
| 914 } | 364 } |
| 915 | 365 |
| 916 void NativeAppWindowViews::UpdateDraggableRegions( | 366 void NativeAppWindowViews::UpdateDraggableRegions( |
| 917 const std::vector<extensions::DraggableRegion>& regions) { | 367 const std::vector<extensions::DraggableRegion>& regions) { |
| 918 // Draggable region is not supported for non-frameless window. | 368 // Draggable region is not supported for non-frameless window. |
| 919 if (!frameless_) | 369 if (!frameless_) |
| 920 return; | 370 return; |
| 921 | 371 |
| 922 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); | 372 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); |
| 923 OnViewWasResized(); | 373 OnViewWasResized(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 417 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 968 gfx::Rect window_bounds = | 418 gfx::Rect window_bounds = |
| 969 window_->non_client_view()->GetWindowBoundsForClientBounds( | 419 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| 970 client_bounds); | 420 client_bounds); |
| 971 return window_bounds.InsetsFrom(client_bounds); | 421 return window_bounds.InsetsFrom(client_bounds); |
| 972 } | 422 } |
| 973 | 423 |
| 974 void NativeAppWindowViews::HideWithApp() {} | 424 void NativeAppWindowViews::HideWithApp() {} |
| 975 void NativeAppWindowViews::ShowWithApp() {} | 425 void NativeAppWindowViews::ShowWithApp() {} |
| 976 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 426 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
| OLD | NEW |