Chromium Code Reviews| 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/frame/browser_frame_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_frame_ash.h" |
| 6 | 6 |
| 7 #include "ash/wm/window_state.h" | 7 #include "ash/wm/window_state.h" |
| 8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "chrome/browser/ui/views/frame/non_client_frame_view_switcher_ash.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_observer.h" | |
| 13 #include "ui/gfx/font.h" | 12 #include "ui/gfx/font.h" |
| 14 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 15 | 14 |
| 16 using aura::Window; | |
| 17 | |
| 18 //////////////////////////////////////////////////////////////////////////////// | |
| 19 // BrowserFrameAsh::WindowPropertyWatcher | |
| 20 | |
| 21 class BrowserFrameAsh::WindowPropertyWatcher : public aura::WindowObserver { | |
| 22 public: | |
| 23 explicit WindowPropertyWatcher(BrowserFrameAsh* browser_frame_ash, | |
| 24 BrowserFrame* browser_frame) | |
| 25 : browser_frame_ash_(browser_frame_ash), | |
| 26 browser_frame_(browser_frame) {} | |
| 27 | |
| 28 virtual void OnWindowPropertyChanged(aura::Window* window, | |
| 29 const void* key, | |
| 30 intptr_t old) OVERRIDE { | |
| 31 if (key != aura::client::kShowStateKey) | |
| 32 return; | |
| 33 | |
| 34 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | |
| 35 ui::WindowShowState new_state = | |
| 36 window->GetProperty(aura::client::kShowStateKey); | |
| 37 | |
| 38 // Allow the frame to be replaced when entering or exiting the maximized | |
| 39 // state. | |
| 40 if (browser_frame_->non_client_view() && | |
| 41 browser_frame_ash_->browser_view()->browser()->is_app() && | |
| 42 (old_state == ui::SHOW_STATE_MAXIMIZED || | |
| 43 new_state == ui::SHOW_STATE_MAXIMIZED)) { | |
| 44 // Defer frame layout when replacing the frame. Layout will occur when the | |
| 45 // window's bounds are updated. The window maximize/restore animations | |
| 46 // clone the window's layers and rely on the subsequent layout to set | |
| 47 // the layer sizes. | |
| 48 // If the window is minimized, the frame view needs to be updated via | |
| 49 // an OnBoundsChanged event so that the frame will change its size | |
| 50 // properly. | |
| 51 browser_frame_->non_client_view()->UpdateFrame( | |
| 52 old_state == ui::SHOW_STATE_MINIMIZED); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 virtual void OnWindowBoundsChanged(aura::Window* window, | |
| 57 const gfx::Rect& old_bounds, | |
| 58 const gfx::Rect& new_bounds) OVERRIDE { | |
| 59 // Don't do anything if we don't have our non-client view yet. | |
|
pkotwicz
2013/10/02 19:41:49
Removed this method because it is obsolete
| |
| 60 if (!browser_frame_->non_client_view()) | |
| 61 return; | |
| 62 | |
| 63 // If the window just moved to the top of the screen, or just moved away | |
| 64 // from it, invoke Layout() so the header size can change. | |
| 65 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || | |
| 66 (old_bounds.y() != 0 && new_bounds.y() == 0)) | |
| 67 browser_frame_->non_client_view()->Layout(); | |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 BrowserFrameAsh* browser_frame_ash_; | |
| 72 BrowserFrame* browser_frame_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(WindowPropertyWatcher); | |
| 75 }; | |
| 76 | |
| 77 /////////////////////////////////////////////////////////////////////////////// | 15 /////////////////////////////////////////////////////////////////////////////// |
| 78 // BrowserFrameAsh, public: | 16 // BrowserFrameAsh, public: |
| 79 | 17 |
| 80 // static | 18 // static |
| 81 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh"; | 19 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh"; |
| 82 | 20 |
| 83 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame, | 21 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame, |
| 84 BrowserView* browser_view) | 22 BrowserView* browser_view) |
| 85 : views::NativeWidgetAura(browser_frame), | 23 : views::NativeWidgetAura(browser_frame), |
| 86 browser_view_(browser_view), | 24 browser_view_(browser_view) { |
| 87 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { | |
| 88 GetNativeWindow()->SetName(kWindowName); | 25 GetNativeWindow()->SetName(kWindowName); |
| 89 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | 26 if (browser_view->browser()->is_app()) { |
| 27 // Apps switch to a special non client frame view when maximized. | |
| 28 browser_frame_switcher_.reset(new NonClientFrameViewSwitcherAsh( | |
| 29 browser_frame, GetNativeWindow())); | |
| 30 } | |
| 31 | |
| 90 if (browser_view->browser()->is_type_tabbed()) | 32 if (browser_view->browser()->is_type_tabbed()) |
| 91 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); | 33 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); |
| 92 | 34 |
| 93 // Turn on auto window management if we don't need an explicit bounds. | 35 // Turn on auto window management if we don't need an explicit bounds. |
| 94 // This way the requested bounds are honored. | 36 // This way the requested bounds are honored. |
| 95 if (!browser_view->browser()->bounds_overridden() && | 37 if (!browser_view->browser()->bounds_overridden() && |
| 96 !browser_view->browser()->is_session_restore()) | 38 !browser_view->browser()->is_session_restore()) |
| 97 SetWindowAutoManaged(); | 39 SetWindowAutoManaged(); |
| 98 } | 40 } |
| 99 | 41 |
| 100 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
| 101 // BrowserFrameAsh, views::NativeWidgetAura overrides: | 43 // BrowserFrameAsh, views::NativeWidgetAura override: |
| 102 | |
| 103 void BrowserFrameAsh::OnWindowDestroying() { | |
| 104 // Window is destroyed before our destructor is called, so clean up our | |
| 105 // observer here. | |
| 106 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); | |
| 107 views::NativeWidgetAura::OnWindowDestroying(); | |
| 108 } | |
| 109 | 44 |
| 110 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool visible) { | 45 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool visible) { |
| 111 if (visible) { | 46 if (visible) { |
| 112 // Once the window has been shown we know the requested bounds | 47 // Once the window has been shown we know the requested bounds |
| 113 // (if provided) have been honored and we can switch on window management. | 48 // (if provided) have been honored and we can switch on window management. |
| 114 SetWindowAutoManaged(); | 49 SetWindowAutoManaged(); |
| 115 } | 50 } |
| 116 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); | 51 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); |
| 117 } | 52 } |
| 118 | 53 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 BrowserFrameAsh::~BrowserFrameAsh() { | 88 BrowserFrameAsh::~BrowserFrameAsh() { |
| 154 } | 89 } |
| 155 | 90 |
| 156 void BrowserFrameAsh::SetWindowAutoManaged() { | 91 void BrowserFrameAsh::SetWindowAutoManaged() { |
| 157 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || | 92 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || |
| 158 browser_view_->browser()->is_app()) { | 93 browser_view_->browser()->is_app()) { |
| 159 ash::wm::GetWindowState(GetNativeWindow())-> | 94 ash::wm::GetWindowState(GetNativeWindow())-> |
| 160 set_window_position_managed(true); | 95 set_window_position_managed(true); |
| 161 } | 96 } |
| 162 } | 97 } |
| OLD | NEW |