Chromium Code Reviews| Index: chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc b/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| index 440274f4bb2ba8b2e32f501599a2d5f8610d8dba..fc757d2420b1561dfa4d14ee9573a423de150b31 100644 |
| --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc |
| @@ -5,57 +5,24 @@ |
| #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" |
| #include "apps/ui/views/app_window_frame_view.h" |
| -#include "base/command_line.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/app_mode/app_mode_utils.h" |
| #include "chrome/browser/favicon/favicon_tab_helper.h" |
| #include "chrome/browser/profiles/profile.h" |
| -#include "chrome/browser/ui/host_desktop.h" |
| #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h" |
| -#include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" |
| #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h" |
| #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
| #include "chrome/browser/web_applications/web_app.h" |
| -#include "chrome/common/chrome_switches.h" |
| #include "components/ui/zoom/page_zoom.h" |
| #include "components/ui/zoom/zoom_controller.h" |
| -#include "extensions/common/extension.h" |
| #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.
|
| -#include "ui/base/hit_test.h" |
| -#include "ui/base/models/simple_menu_model.h" |
| -#include "ui/gfx/image/image_skia.h" |
| -#include "ui/views/controls/menu/menu_runner.h" |
| #include "ui/views/controls/webview/webview.h" |
| #include "ui/views/widget/widget.h" |
| -#include "ui/wm/core/easy_resize_window_targeter.h" |
| #if defined(OS_LINUX) |
| #include "chrome/browser/shell_integration_linux.h" |
| #endif |
| -#if defined(USE_ASH) |
| -#include "ash/ash_constants.h" |
| -#include "ash/ash_switches.h" |
| -#include "ash/frame/custom_frame_view_ash.h" |
| -#include "ash/screen_util.h" |
| -#include "ash/shell.h" |
| -#include "ash/wm/immersive_fullscreen_controller.h" |
| -#include "ash/wm/panels/panel_frame_view.h" |
| -#include "ash/wm/window_properties.h" |
| -#include "ash/wm/window_state.h" |
| -#include "ash/wm/window_state_delegate.h" |
| -#include "ash/wm/window_state_observer.h" |
| -#include "chrome/browser/ui/ash/ash_util.h" |
| -#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
| -#include "ui/aura/client/aura_constants.h" |
| -#include "ui/aura/client/window_tree_client.h" |
| -#include "ui/aura/window_observer.h" |
| -#endif |
| - |
| -#if defined(OS_CHROMEOS) |
| -#include "ash/shell_window_ids.h" |
| -#endif |
| - |
| using extensions::AppWindow; |
| namespace { |
| @@ -122,76 +89,6 @@ const std::map<ui::Accelerator, int>& GetAcceleratorTable() { |
| return accelerators; |
| } |
| -#if defined(USE_ASH) |
| -// This class handles a user's fullscreen request (Shift+F4/F4). |
| -class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, |
| - public ash::wm::WindowStateObserver, |
| - public aura::WindowObserver { |
| - public: |
| - NativeAppWindowStateDelegate(AppWindow* app_window, |
| - extensions::NativeAppWindow* native_app_window) |
| - : app_window_(app_window), |
| - window_state_( |
| - ash::wm::GetWindowState(native_app_window->GetNativeWindow())) { |
| - // Add a window state observer to exit fullscreen properly in case |
| - // fullscreen is exited without going through AppWindow::Restore(). This |
| - // is the case when exiting immersive fullscreen via the "Restore" window |
| - // control. |
| - // TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048 |
| - window_state_->AddObserver(this); |
| - window_state_->window()->AddObserver(this); |
| - } |
| - ~NativeAppWindowStateDelegate() override { |
| - if (window_state_) { |
| - window_state_->RemoveObserver(this); |
| - window_state_->window()->RemoveObserver(this); |
| - } |
| - } |
| - |
| - private: |
| - // Overridden from ash::wm::WindowStateDelegate. |
| - bool ToggleFullscreen(ash::wm::WindowState* window_state) override { |
| - // Windows which cannot be maximized should not be fullscreened. |
| - DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); |
| - if (window_state->IsFullscreen()) |
| - app_window_->Restore(); |
| - else if (window_state->CanMaximize()) |
| - app_window_->OSFullscreen(); |
| - return true; |
| - } |
| - |
| - // Overridden from ash::wm::WindowStateObserver: |
| - void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, |
| - ash::wm::WindowStateType old_type) override { |
| - // Since the window state might get set by a window manager, it is possible |
| - // to come here before the application set its |BaseWindow|. |
| - if (!window_state->IsFullscreen() && !window_state->IsMinimized() && |
| - app_window_->GetBaseWindow() && |
| - app_window_->GetBaseWindow()->IsFullscreenOrPending()) { |
| - app_window_->Restore(); |
| - // Usually OnNativeWindowChanged() is called when the window bounds are |
| - // changed as a result of a state type change. Because the change in state |
| - // type has already occurred, we need to call OnNativeWindowChanged() |
| - // explicitly. |
| - app_window_->OnNativeWindowChanged(); |
| - } |
| - } |
| - |
| - // Overridden from aura::WindowObserver: |
| - void OnWindowDestroying(aura::Window* window) override { |
| - window_state_->RemoveObserver(this); |
| - window_state_->window()->RemoveObserver(this); |
| - window_state_ = NULL; |
| - } |
| - |
| - // Not owned. |
| - AppWindow* app_window_; |
| - ash::wm::WindowState* window_state_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); |
| -}; |
| -#endif // USE_ASH |
| - |
| } // namespace |
| ChromeNativeAppWindowViews::ChromeNativeAppWindowViews() |
| @@ -243,9 +140,7 @@ void ChromeNativeAppWindowViews::InitializeDefaultWindow( |
| #if defined(OS_CHROMEOS) |
| if (create_params.is_ime_window) { |
| // Puts ime windows into ime window container. |
| - init_params.parent = |
| - ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), |
| - ash::kShellWindowId_ImeWindowParentContainer); |
| + 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 :).
|
| } |
| #endif |
| widget()->Init(init_params); |
| @@ -305,6 +200,10 @@ void ChromeNativeAppWindowViews::InitializeDefaultWindow( |
| } |
| } |
| +gfx::NativeView ChromeNativeAppWindowViews::GetImeWindowContainer() { |
| + return nullptr; |
| +} |
| + |
| void ChromeNativeAppWindowViews::InitializePanelWindow( |
| const AppWindow::CreateParams& create_params) { |
| views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
| @@ -323,132 +222,48 @@ void ChromeNativeAppWindowViews::InitializePanelWindow( |
| preferred_size_.set_height(kDefaultPanelHeight); |
| else if (preferred_size_.height() < kMinPanelHeight) |
| preferred_size_.set_height(kMinPanelHeight); |
| -#if defined(USE_ASH) |
| - if (ash::Shell::HasInstance()) { |
| - // Open a new panel on the target root. |
| - aura::Window* target = ash::Shell::GetTargetRootWindow(); |
| - params.bounds = ash::ScreenUtil::ConvertRectToScreen( |
| - target, gfx::Rect(preferred_size_)); |
| - } else { |
| - params.bounds = gfx::Rect(preferred_size_); |
| - } |
| -#else |
| - params.bounds = gfx::Rect(preferred_size_); |
| -#endif |
| + |
| + params.bounds = GetPanelWindowInitialBounds(preferred_size_); |
| 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.
|
| widget()->set_focus_on_creation(create_params.focused); |
| } |
| +gfx::Rect ChromeNativeAppWindowViews::GetPanelWindowInitialBounds( |
| + gfx::Size preferred_size_) { |
| + return gfx::Rect(preferred_size_); |
| +} |
| + |
| views::NonClientFrameView* |
| ChromeNativeAppWindowViews::CreateStandardDesktopAppFrame() { |
| return views::WidgetDelegateView::CreateNonClientFrameView(widget()); |
| } |
| +apps::AppWindowFrameView* |
| +ChromeNativeAppWindowViews::CreateNonStandardAppFrame() { |
| + apps::AppWindowFrameView* frame = |
| + new apps::AppWindowFrameView(widget(), this, has_frame_color_, |
| + active_frame_color_, inactive_frame_color_); |
| + frame->Init(); |
| + return frame; |
| +} |
| + |
| // ui::BaseWindow implementation. |
| gfx::Rect ChromeNativeAppWindowViews::GetRestoredBounds() const { |
| -#if defined(USE_ASH) |
| - gfx::Rect* bounds = widget()->GetNativeWindow()->GetProperty( |
| - ash::kRestoreBoundsOverrideKey); |
| - if (bounds && !bounds->IsEmpty()) |
| - return *bounds; |
| -#endif |
| return widget()->GetRestoredBounds(); |
| } |
| ui::WindowShowState ChromeNativeAppWindowViews::GetRestoredState() const { |
| -#if !defined(USE_ASH) |
| if (IsMaximized()) |
| return ui::SHOW_STATE_MAXIMIZED; |
|
tapted
2015/02/25 05:54:35
hm - this line is essentially dead -- #ifdef'd out
|
| if (IsFullscreen()) |
| return ui::SHOW_STATE_FULLSCREEN; |
| -#else |
| - // Use kRestoreShowStateKey in case a window is minimized/hidden. |
| - ui::WindowShowState restore_state = widget()->GetNativeWindow()->GetProperty( |
| - aura::client::kRestoreShowStateKey); |
| - if (widget()->GetNativeWindow()->GetProperty( |
| - ash::kRestoreBoundsOverrideKey)) { |
| - // If an override is given, we use that restore state (after filtering). |
| - restore_state = widget()->GetNativeWindow()->GetProperty( |
| - ash::kRestoreShowStateOverrideKey); |
| - } else { |
| - // Otherwise first normal states are checked. |
| - if (IsMaximized()) |
| - return ui::SHOW_STATE_MAXIMIZED; |
| - if (IsFullscreen()) { |
| - if (immersive_fullscreen_controller_.get() && |
| - immersive_fullscreen_controller_->IsEnabled()) { |
| - // Restore windows which were previously in immersive fullscreen to |
| - // maximized. Restoring the window to a different fullscreen type |
| - // makes for a bad experience. |
| - return ui::SHOW_STATE_MAXIMIZED; |
| - } |
| - return ui::SHOW_STATE_FULLSCREEN; |
| - } |
| - } |
| - // Whitelist states to return so that invalid and transient states |
| - // are not saved and used to restore windows when they are recreated. |
| - switch (restore_state) { |
| - case ui::SHOW_STATE_NORMAL: |
| - case ui::SHOW_STATE_MAXIMIZED: |
| - case ui::SHOW_STATE_FULLSCREEN: |
| - return restore_state; |
| - |
| - case ui::SHOW_STATE_DEFAULT: |
| - case ui::SHOW_STATE_MINIMIZED: |
| - case ui::SHOW_STATE_INACTIVE: |
| - case ui::SHOW_STATE_END: |
| - return ui::SHOW_STATE_NORMAL; |
| - } |
| -#endif // !defined(USE_ASH) |
| + |
| return ui::SHOW_STATE_NORMAL; |
| } |
| bool ChromeNativeAppWindowViews::IsAlwaysOnTop() const { |
| - if (app_window()->window_type_is_panel()) { |
| -#if defined(USE_ASH) |
| - return ash::wm::GetWindowState(widget()->GetNativeWindow()) |
| - ->panel_attached(); |
| -#else |
| - return true; |
| -#endif |
| - } else { |
| - return widget()->IsAlwaysOnTop(); |
| - } |
| -} |
| - |
| -// views::ContextMenuController implementation. |
| - |
| -void ChromeNativeAppWindowViews::ShowContextMenuForView( |
| - views::View* source, |
| - const gfx::Point& p, |
| - ui::MenuSourceType source_type) { |
| -#if defined(USE_ASH) && defined(OS_CHROMEOS) |
| - scoped_ptr<ui::MenuModel> model = |
| - CreateMultiUserContextMenu(app_window()->GetNativeWindow()); |
| - if (!model.get()) |
| - return; |
| - |
| - // Only show context menu if point is in caption. |
| - gfx::Point point_in_view_coords(p); |
| - views::View::ConvertPointFromScreen(widget()->non_client_view(), |
| - &point_in_view_coords); |
| - int hit_test = |
| - widget()->non_client_view()->NonClientHitTest(point_in_view_coords); |
| - if (hit_test == HTCAPTION) { |
| - menu_runner_.reset(new views::MenuRunner( |
| - model.get(), |
| - views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); |
| - if (menu_runner_->RunMenuAt(source->GetWidget(), |
| - NULL, |
| - gfx::Rect(p, gfx::Size(0, 0)), |
| - views::MENU_ANCHOR_TOPLEFT, |
| - source_type) == |
| - views::MenuRunner::MENU_DELETED) { |
| - return; |
| - } |
| - } |
| -#endif |
| + 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.
|
| } |
| // views::WidgetDelegate implementation. |
| @@ -475,41 +290,6 @@ gfx::ImageSkia ChromeNativeAppWindowViews::GetWindowIcon() { |
| views::NonClientFrameView* ChromeNativeAppWindowViews::CreateNonClientFrameView( |
| views::Widget* widget) { |
| -#if defined(USE_ASH) |
| - if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| - // Set the delegate now because CustomFrameViewAsh sets the |
| - // WindowStateDelegate if one is not already set. |
| - ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( |
| - scoped_ptr<ash::wm::WindowStateDelegate>( |
| - new NativeAppWindowStateDelegate(app_window(), this)).Pass()); |
| - |
| - if (IsFrameless()) |
| - return CreateNonStandardAppFrame(); |
| - |
| - if (app_window()->window_type_is_panel()) { |
| - views::NonClientFrameView* frame_view = |
| - new ash::PanelFrameView(widget, ash::PanelFrameView::FRAME_ASH); |
| - frame_view->set_context_menu_controller(this); |
| - return frame_view; |
| - } |
| - |
| - ash::CustomFrameViewAsh* custom_frame_view = |
| - new ash::CustomFrameViewAsh(widget); |
| - // Non-frameless app windows can be put into immersive fullscreen. |
| - immersive_fullscreen_controller_.reset( |
| - new ash::ImmersiveFullscreenController()); |
| - custom_frame_view->InitImmersiveFullscreenControllerForView( |
| - immersive_fullscreen_controller_.get()); |
| - custom_frame_view->GetHeaderView()->set_context_menu_controller(this); |
| - |
| - if (has_frame_color_) { |
| - custom_frame_view->SetFrameColors(active_frame_color_, |
| - inactive_frame_color_); |
| - } |
| - |
| - return custom_frame_view; |
| - } |
| -#endif |
| return (IsFrameless() || has_frame_color_) ? |
| CreateNonStandardAppFrame() : CreateStandardDesktopAppFrame(); |
| } |
| @@ -569,24 +349,6 @@ void ChromeNativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
| widget()->SetFullscreen(is_fullscreen_); |
| -#if defined(USE_ASH) |
| - if (immersive_fullscreen_controller_.get()) { |
| - // |immersive_fullscreen_controller_| should only be set if immersive |
| - // fullscreen is the fullscreen type used by the OS. |
| - immersive_fullscreen_controller_->SetEnabled( |
| - ash::ImmersiveFullscreenController::WINDOW_TYPE_PACKAGED_APP, |
| - (fullscreen_types & AppWindow::FULLSCREEN_TYPE_OS) != 0); |
| - // Autohide the shelf instead of hiding the shelf completely when only in |
| - // OS fullscreen. |
| - ash::wm::WindowState* window_state = |
| - ash::wm::GetWindowState(widget()->GetNativeWindow()); |
| - window_state->set_hide_shelf_when_fullscreen(fullscreen_types != |
| - AppWindow::FULLSCREEN_TYPE_OS); |
| - DCHECK(ash::Shell::HasInstance()); |
| - ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| - } |
| -#endif |
| - |
| // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| // ever drop the window out of fullscreen in response to something that |
| // wasn't the app calling webkitCancelFullScreen(). |
| @@ -613,21 +375,7 @@ void ChromeNativeAppWindowViews::UpdateBadgeIcon() { |
| } |
| void ChromeNativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { |
| - bool had_shape = shape_; |
| shape_ = region.Pass(); |
| - |
| - aura::Window* native_window = widget()->GetNativeWindow(); |
| - if (shape_) { |
| - widget()->SetShape(new SkRegion(*shape_)); |
| - if (!had_shape) { |
| - native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
| - new ShapedAppWindowTargeter(native_window, this))); |
| - } |
| - } else { |
| - widget()->SetShape(NULL); |
| - if (had_shape) |
| - native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); |
| - } |
| widget()->OnSizeConstraintsChanged(); |
| } |
| @@ -672,42 +420,3 @@ void ChromeNativeAppWindowViews::InitializeWindow( |
| extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| NULL)); |
| } |
| - |
| -apps::AppWindowFrameView* |
| -ChromeNativeAppWindowViews::CreateNonStandardAppFrame() { |
| - apps::AppWindowFrameView* frame = |
| - new apps::AppWindowFrameView(widget(), |
| - this, |
| - has_frame_color_, |
| - active_frame_color_, |
| - inactive_frame_color_); |
| - frame->Init(); |
| -#if defined(USE_ASH) |
| - // For Aura windows on the Ash desktop the sizes are different and the user |
| - // can resize the window from slightly outside the bounds as well. |
| - if (chrome::IsNativeWindowInAsh(widget()->GetNativeWindow())) { |
| - frame->SetResizeSizes(ash::kResizeInsideBoundsSize, |
| - ash::kResizeOutsideBoundsSize, |
| - ash::kResizeAreaCornerSize); |
| - } |
| -#endif |
| - |
| -#if !defined(OS_CHROMEOS) |
| - // For non-Ash windows, install an easy resize window targeter, which ensures |
| - // that the root window (not the app) receives mouse events on the edges. |
| - if (chrome::GetHostDesktopTypeForNativeWindow(widget()->GetNativeWindow()) != |
| - chrome::HOST_DESKTOP_TYPE_ASH) { |
| - aura::Window* window = widget()->GetNativeWindow(); |
| - int resize_inside = frame->resize_inside_bounds_size(); |
| - gfx::Insets inset( |
| - resize_inside, resize_inside, resize_inside, resize_inside); |
| - // Add the EasyResizeWindowTargeter on the window, not its root window. The |
| - // root window does not have a delegate, which is needed to handle the event |
| - // in Linux. |
| - window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
| - new wm::EasyResizeWindowTargeter(window, inset, inset))); |
| - } |
| -#endif |
| - |
| - return frame; |
| -} |