| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/frame/browser_frame_aura.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "chrome/app/chrome_command_ids.h" | |
| 9 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 10 #include "grit/chromium_strings.h" | |
| 11 #include "grit/generated_resources.h" | |
| 12 #include "ui/aura/client/aura_constants.h" | |
| 13 #include "ui/aura/window.h" | |
| 14 #include "ui/aura/window_observer.h" | |
| 15 #include "ui/base/hit_test.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/gfx/font.h" | |
| 18 #include "ui/views/view.h" | |
| 19 | |
| 20 #if defined(USE_ASH) | |
| 21 #include "ash/wm/window_state.h" | |
| 22 #include "ash/wm/window_util.h" | |
| 23 #endif | |
| 24 | |
| 25 using aura::Window; | |
| 26 | |
| 27 //////////////////////////////////////////////////////////////////////////////// | |
| 28 // BrowserFrameAura::WindowPropertyWatcher | |
| 29 | |
| 30 class BrowserFrameAura::WindowPropertyWatcher : public aura::WindowObserver { | |
| 31 public: | |
| 32 explicit WindowPropertyWatcher(BrowserFrameAura* browser_frame_aura, | |
| 33 BrowserFrame* browser_frame) | |
| 34 : browser_frame_aura_(browser_frame_aura), | |
| 35 browser_frame_(browser_frame) {} | |
| 36 | |
| 37 virtual void OnWindowPropertyChanged(aura::Window* window, | |
| 38 const void* key, | |
| 39 intptr_t old) OVERRIDE { | |
| 40 if (key != aura::client::kShowStateKey) | |
| 41 return; | |
| 42 | |
| 43 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | |
| 44 ui::WindowShowState new_state = | |
| 45 window->GetProperty(aura::client::kShowStateKey); | |
| 46 | |
| 47 // Allow the frame to be replaced when entering or exiting the maximized | |
| 48 // state. | |
| 49 if (browser_frame_->non_client_view() && | |
| 50 browser_frame_aura_->browser_view()->browser()->is_app() && | |
| 51 (old_state == ui::SHOW_STATE_MAXIMIZED || | |
| 52 new_state == ui::SHOW_STATE_MAXIMIZED)) { | |
| 53 // Defer frame layout when replacing the frame. Layout will occur when the | |
| 54 // window's bounds are updated. The window maximize/restore animations | |
| 55 // clone the window's layers and rely on the subsequent layout to set | |
| 56 // the layer sizes. | |
| 57 // If the window is minimized, the frame view needs to be updated via | |
| 58 // an OnBoundsChanged event so that the frame will change its size | |
| 59 // properly. | |
| 60 browser_frame_->non_client_view()->UpdateFrame( | |
| 61 old_state == ui::SHOW_STATE_MINIMIZED); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 virtual void OnWindowBoundsChanged(aura::Window* window, | |
| 66 const gfx::Rect& old_bounds, | |
| 67 const gfx::Rect& new_bounds) OVERRIDE { | |
| 68 // Don't do anything if we don't have our non-client view yet. | |
| 69 if (!browser_frame_->non_client_view()) | |
| 70 return; | |
| 71 | |
| 72 // If the window just moved to the top of the screen, or just moved away | |
| 73 // from it, invoke Layout() so the header size can change. | |
| 74 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || | |
| 75 (old_bounds.y() != 0 && new_bounds.y() == 0)) | |
| 76 browser_frame_->non_client_view()->Layout(); | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 BrowserFrameAura* browser_frame_aura_; | |
| 81 BrowserFrame* browser_frame_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(WindowPropertyWatcher); | |
| 84 }; | |
| 85 | |
| 86 /////////////////////////////////////////////////////////////////////////////// | |
| 87 // BrowserFrameAura, public: | |
| 88 | |
| 89 // static | |
| 90 const char BrowserFrameAura::kWindowName[] = "BrowserFrameAura"; | |
| 91 | |
| 92 BrowserFrameAura::BrowserFrameAura(BrowserFrame* browser_frame, | |
| 93 BrowserView* browser_view) | |
| 94 : views::NativeWidgetAura(browser_frame), | |
| 95 browser_view_(browser_view), | |
| 96 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { | |
| 97 GetNativeWindow()->SetName(kWindowName); | |
| 98 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | |
| 99 #if defined(USE_ASH) | |
| 100 if (browser_view->browser()->is_type_tabbed()) | |
| 101 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); | |
| 102 | |
| 103 // Turn on auto window management if we don't need an explicit bounds. | |
| 104 // This way the requested bounds are honored. | |
| 105 if (!browser_view->browser()->bounds_overridden() && | |
| 106 !browser_view->browser()->is_session_restore()) | |
| 107 SetWindowAutoManaged(); | |
| 108 #endif | |
| 109 #if defined(OS_CHROMEOS) | |
| 110 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys | |
| 111 // like brightness, volume, etc. Otherwise these keys are handled by the | |
| 112 // Ash window manager. | |
| 113 if (browser_view->browser()->is_app()) { | |
| 114 ash::wm::GetWindowState(GetNativeWindow())-> | |
| 115 set_can_consume_system_keys(true); | |
| 116 } | |
| 117 #endif // defined(OS_CHROMEOS) | |
| 118 } | |
| 119 | |
| 120 /////////////////////////////////////////////////////////////////////////////// | |
| 121 // BrowserFrameAura, views::NativeWidgetAura overrides: | |
| 122 | |
| 123 void BrowserFrameAura::OnWindowDestroying() { | |
| 124 // Window is destroyed before our destructor is called, so clean up our | |
| 125 // observer here. | |
| 126 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); | |
| 127 views::NativeWidgetAura::OnWindowDestroying(); | |
| 128 } | |
| 129 | |
| 130 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { | |
| 131 if (visible) { | |
| 132 // Once the window has been shown we know the requested bounds | |
| 133 // (if provided) have been honored and we can switch on window management. | |
| 134 SetWindowAutoManaged(); | |
| 135 } | |
| 136 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); | |
| 137 } | |
| 138 | |
| 139 //////////////////////////////////////////////////////////////////////////////// | |
| 140 // BrowserFrameAura, NativeBrowserFrame implementation: | |
| 141 | |
| 142 views::NativeWidget* BrowserFrameAura::AsNativeWidget() { | |
| 143 return this; | |
| 144 } | |
| 145 | |
| 146 const views::NativeWidget* BrowserFrameAura::AsNativeWidget() const { | |
| 147 return this; | |
| 148 } | |
| 149 | |
| 150 bool BrowserFrameAura::UsesNativeSystemMenu() const { | |
| 151 return false; | |
| 152 } | |
| 153 | |
| 154 int BrowserFrameAura::GetMinimizeButtonOffset() const { | |
| 155 return 0; | |
| 156 } | |
| 157 | |
| 158 void BrowserFrameAura::TabStripDisplayModeChanged() { | |
| 159 } | |
| 160 | |
| 161 //////////////////////////////////////////////////////////////////////////////// | |
| 162 // BrowserFrame, public: | |
| 163 | |
| 164 // static | |
| 165 const gfx::Font& BrowserFrame::GetTitleFont() { | |
| 166 static gfx::Font* title_font = new gfx::Font; | |
| 167 return *title_font; | |
| 168 } | |
| 169 | |
| 170 /////////////////////////////////////////////////////////////////////////////// | |
| 171 // BrowserFrameAura, private: | |
| 172 | |
| 173 BrowserFrameAura::~BrowserFrameAura() { | |
| 174 } | |
| 175 | |
| 176 void BrowserFrameAura::SetWindowAutoManaged() { | |
| 177 #if defined(USE_ASH) | |
| 178 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || | |
| 179 browser_view_->browser()->is_app()) { | |
| 180 ash::wm::GetWindowState(GetNativeWindow())-> | |
| 181 set_window_position_managed(true); | |
| 182 } | |
| 183 #endif | |
| 184 } | |
| OLD | NEW |