OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/extensions/native_app_window_views.h" | 5 #include "chrome/browser/ui/views/extensions/native_app_window_views.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
8 #include "chrome/browser/favicon/favicon_tab_helper.h" | 8 #include "chrome/browser/favicon/favicon_tab_helper.h" |
9 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 9 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
10 #include "chrome/browser/ui/views/extensions/shell_window_frame_view.h" | 10 #include "chrome/browser/ui/views/extensions/shell_window_frame_view.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 web_view_(NULL), | 49 web_view_(NULL), |
50 window_(NULL), | 50 window_(NULL), |
51 is_fullscreen_(false), | 51 is_fullscreen_(false), |
52 frameless_(create_params.frame == ShellWindow::FRAME_NONE), | 52 frameless_(create_params.frame == ShellWindow::FRAME_NONE), |
53 transparent_background_(create_params.transparent_background) { | 53 transparent_background_(create_params.transparent_background) { |
54 Observe(shell_window_->web_contents()); | 54 Observe(shell_window_->web_contents()); |
55 minimum_size_ = create_params.minimum_size; | 55 minimum_size_ = create_params.minimum_size; |
56 maximum_size_ = create_params.maximum_size; | 56 maximum_size_ = create_params.maximum_size; |
57 | 57 |
58 window_ = new views::Widget; | 58 window_ = new views::Widget; |
59 if (create_params.window_type == ShellWindow::WINDOW_TYPE_PANEL) | 59 if (create_params.window_type == ShellWindow::WINDOW_TYPE_PANEL || |
60 create_params.window_type == ShellWindow::WINDOW_TYPE_V1_PANEL) { | |
60 InitializePanelWindow(create_params); | 61 InitializePanelWindow(create_params); |
61 else | 62 } else { |
62 InitializeDefaultWindow(create_params); | 63 InitializeDefaultWindow(create_params); |
63 | 64 } |
64 extension_keybinding_registry_.reset( | 65 extension_keybinding_registry_.reset( |
65 new ExtensionKeybindingRegistryViews( | 66 new ExtensionKeybindingRegistryViews( |
66 profile(), | 67 profile(), |
67 window_->GetFocusManager(), | 68 window_->GetFocusManager(), |
68 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 69 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
69 shell_window_)); | 70 shell_window_)); |
70 | 71 |
71 OnViewWasResized(); | 72 OnViewWasResized(); |
72 window_->AddObserver(this); | 73 window_->AddObserver(this); |
73 } | 74 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 139 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
139 // could plumb context through to here in some cases. | 140 // could plumb context through to here in some cases. |
140 params.top_level = true; | 141 params.top_level = true; |
141 window_->Init(params); | 142 window_->Init(params); |
142 | 143 |
143 #if !defined(USE_ASH) | 144 #if !defined(USE_ASH) |
144 // TODO(oshima|stevenjb): Ideally, we should be able to just pre-determine | 145 // TODO(oshima|stevenjb): Ideally, we should be able to just pre-determine |
145 // the exact location and size, but this doesn't work well | 146 // the exact location and size, but this doesn't work well |
146 // on non-ash environment where we don't have full control over | 147 // on non-ash environment where we don't have full control over |
147 // window management. | 148 // window management. |
148 gfx::Rect window_bounds = | 149 if (ash::Shell::HasInstance()) { |
jeremya
2013/02/15 03:28:16
not sure I understand this -- won't the 'ash' name
stevenjb
2013/02/15 18:26:35
This was a mistake and will be removed.
| |
149 window_->non_client_view()->GetWindowBoundsForClientBounds( | 150 gfx::Rect window_bounds = |
150 create_params.bounds); | 151 window_->non_client_view()->GetWindowBoundsForClientBounds( |
151 window_->SetBounds(window_bounds); | 152 create_params.bounds); |
153 window_->SetBounds(window_bounds); | |
154 } | |
152 #endif | 155 #endif |
153 } | 156 } |
154 | 157 |
155 // BaseWindow implementation. | 158 // BaseWindow implementation. |
156 | 159 |
157 bool NativeAppWindowViews::IsActive() const { | 160 bool NativeAppWindowViews::IsActive() const { |
158 return window_->IsActive(); | 161 return window_->IsActive(); |
159 } | 162 } |
160 | 163 |
161 bool NativeAppWindowViews::IsMaximized() const { | 164 bool NativeAppWindowViews::IsMaximized() const { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 | 230 |
228 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { | 231 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { |
229 GetWidget()->SetBounds(bounds); | 232 GetWidget()->SetBounds(bounds); |
230 } | 233 } |
231 | 234 |
232 void NativeAppWindowViews::FlashFrame(bool flash) { | 235 void NativeAppWindowViews::FlashFrame(bool flash) { |
233 window_->FlashFrame(flash); | 236 window_->FlashFrame(flash); |
234 } | 237 } |
235 | 238 |
236 bool NativeAppWindowViews::IsAlwaysOnTop() const { | 239 bool NativeAppWindowViews::IsAlwaysOnTop() const { |
237 return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL; | 240 return shell_window_->window_type_panel(); |
238 } | 241 } |
239 | 242 |
240 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 243 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { |
241 if (frameless()) | 244 if (frameless()) |
242 return gfx::Insets(); | 245 return gfx::Insets(); |
243 | 246 |
244 // The pretend client_bounds passed in need to be large enough to ensure that | 247 // The pretend client_bounds passed in need to be large enough to ensure that |
245 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 248 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
246 // the specified amount of space to fit the window controls in, and return a | 249 // the specified amount of space to fit the window controls in, and return a |
247 // number larger than the real frame insets. Most window controls are smaller | 250 // number larger than the real frame insets. Most window controls are smaller |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 326 |
324 bool NativeAppWindowViews::CanMaximize() const { | 327 bool NativeAppWindowViews::CanMaximize() const { |
325 return maximum_size_.IsEmpty(); | 328 return maximum_size_.IsEmpty(); |
326 } | 329 } |
327 | 330 |
328 string16 NativeAppWindowViews::GetWindowTitle() const { | 331 string16 NativeAppWindowViews::GetWindowTitle() const { |
329 return shell_window_->GetTitle(); | 332 return shell_window_->GetTitle(); |
330 } | 333 } |
331 | 334 |
332 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 335 bool NativeAppWindowViews::ShouldShowWindowTitle() const { |
333 return false; | 336 return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_V1_PANEL; |
jeremya
2013/02/15 03:28:16
This class is getting pretty tangly :(
stevenjb
2013/02/15 18:26:35
I wasn't in favor of doing the hack, but we decide
| |
334 } | 337 } |
335 | 338 |
336 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { | 339 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { |
337 gfx::Image app_icon = shell_window_->app_icon(); | 340 gfx::Image app_icon = shell_window_->app_icon(); |
338 if (app_icon.IsEmpty()) | 341 if (app_icon.IsEmpty()) |
339 return GetWindowIcon(); | 342 return GetWindowIcon(); |
340 else | 343 else |
341 return *app_icon.ToImageSkia(); | 344 return *app_icon.ToImageSkia(); |
342 } | 345 } |
343 | 346 |
344 gfx::ImageSkia NativeAppWindowViews::GetWindowIcon() { | 347 gfx::ImageSkia NativeAppWindowViews::GetWindowIcon() { |
345 content::WebContents* web_contents = shell_window_->web_contents(); | 348 content::WebContents* web_contents = shell_window_->web_contents(); |
346 if (web_contents) { | 349 if (web_contents) { |
347 FaviconTabHelper* favicon_tab_helper = | 350 FaviconTabHelper* favicon_tab_helper = |
348 FaviconTabHelper::FromWebContents(web_contents); | 351 FaviconTabHelper::FromWebContents(web_contents); |
349 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | 352 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); |
350 if (!app_icon.IsEmpty()) | 353 if (!app_icon.IsEmpty()) |
351 return *app_icon.ToImageSkia(); | 354 return *app_icon.ToImageSkia(); |
352 } | 355 } |
353 return gfx::ImageSkia(); | 356 return gfx::ImageSkia(); |
354 } | 357 } |
355 | 358 |
359 bool NativeAppWindowViews::ShouldShowWindowIcon() const { | |
360 return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_V1_PANEL; | |
jeremya
2013/02/15 03:28:16
What does this do on Windows (or do we never creat
stevenjb
2013/02/15 18:26:35
We won't create V1_PANEL on Windows. That scenario
| |
361 } | |
362 | |
356 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | 363 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, |
357 ui::WindowShowState show_state) { | 364 ui::WindowShowState show_state) { |
358 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 365 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
359 shell_window_->OnNativeWindowChanged(); | 366 shell_window_->OnNativeWindowChanged(); |
360 } | 367 } |
361 | 368 |
362 void NativeAppWindowViews::DeleteDelegate() { | 369 void NativeAppWindowViews::DeleteDelegate() { |
363 window_->RemoveObserver(this); | 370 window_->RemoveObserver(this); |
364 shell_window_->OnNativeClose(); | 371 shell_window_->OnNativeClose(); |
365 } | 372 } |
366 | 373 |
367 views::Widget* NativeAppWindowViews::GetWidget() { | 374 views::Widget* NativeAppWindowViews::GetWidget() { |
368 return window_; | 375 return window_; |
369 } | 376 } |
370 | 377 |
371 const views::Widget* NativeAppWindowViews::GetWidget() const { | 378 const views::Widget* NativeAppWindowViews::GetWidget() const { |
372 return window_; | 379 return window_; |
373 } | 380 } |
374 | 381 |
375 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 382 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
376 views::Widget* widget) { | 383 views::Widget* widget) { |
377 #if defined(USE_ASH) | 384 #if defined(USE_ASH) |
378 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 385 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
379 if (shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL) { | 386 if (shell_window_->window_type_panel()) { |
380 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 387 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
381 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 388 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
382 return new ash::PanelFrameView(widget, frame_type); | 389 return new ash::PanelFrameView(widget, frame_type); |
383 } | 390 } |
384 if (!frameless_) { | 391 if (!frameless_) { |
385 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | 392 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); |
386 frame->Init(widget); | 393 frame->Init(widget); |
387 return frame; | 394 return frame; |
388 } | 395 } |
389 } | 396 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 } | 476 } |
470 | 477 |
471 void NativeAppWindowViews::OnFocus() { | 478 void NativeAppWindowViews::OnFocus() { |
472 web_view_->RequestFocus(); | 479 web_view_->RequestFocus(); |
473 } | 480 } |
474 | 481 |
475 // NativeAppWindow implementation. | 482 // NativeAppWindow implementation. |
476 | 483 |
477 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { | 484 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { |
478 // Fullscreen not supported by panels. | 485 // Fullscreen not supported by panels. |
479 if (shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL) | 486 if (shell_window_->window_type_panel()) |
480 return; | 487 return; |
481 is_fullscreen_ = fullscreen; | 488 is_fullscreen_ = fullscreen; |
482 window_->SetFullscreen(fullscreen); | 489 window_->SetFullscreen(fullscreen); |
483 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 490 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
484 // ever drop the window out of fullscreen in response to something that | 491 // ever drop the window out of fullscreen in response to something that |
485 // wasn't the app calling webkitCancelFullScreen(). | 492 // wasn't the app calling webkitCancelFullScreen(). |
486 } | 493 } |
487 | 494 |
488 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 495 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
489 return is_fullscreen_; | 496 return is_fullscreen_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 } | 529 } |
523 | 530 |
524 //------------------------------------------------------------------------------ | 531 //------------------------------------------------------------------------------ |
525 // NativeAppWindow::Create | 532 // NativeAppWindow::Create |
526 | 533 |
527 // static | 534 // static |
528 NativeAppWindow* NativeAppWindow::Create( | 535 NativeAppWindow* NativeAppWindow::Create( |
529 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 536 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
530 return new NativeAppWindowViews(shell_window, params); | 537 return new NativeAppWindowViews(shell_window, params); |
531 } | 538 } |
OLD | NEW |