| 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/app_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/frame/app_non_client_frame_view_ash.h" |
| 6 | 6 |
| 7 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 7 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
| 8 #include "ash/wm/window_state.h" |
| 9 #include "ash/wm/window_state_delegate.h" |
| 8 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_frame.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 12 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 13 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 17 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
| 18 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 paint_bounds.set_x(view->GetMirroredXForRect(paint_bounds)); | 83 paint_bounds.set_x(view->GetMirroredXForRect(paint_bounds)); |
| 79 canvas->TileImageInt(background_, paint_bounds.x(), paint_bounds.y(), | 84 canvas->TileImageInt(background_, paint_bounds.x(), paint_bounds.y(), |
| 80 paint_bounds.width(), paint_bounds.height()); | 85 paint_bounds.width(), paint_bounds.height()); |
| 81 } | 86 } |
| 82 | 87 |
| 83 gfx::ImageSkia background_; | 88 gfx::ImageSkia background_; |
| 84 | 89 |
| 85 DISALLOW_COPY_AND_ASSIGN(ControlViewBackground); | 90 DISALLOW_COPY_AND_ASSIGN(ControlViewBackground); |
| 86 }; | 91 }; |
| 87 | 92 |
| 93 class FrameWindowStateDelegate : public ash::wm::WindowStateDelegate { |
| 94 public: |
| 95 FrameWindowStateDelegate() {} |
| 96 virtual ~FrameWindowStateDelegate(){} |
| 97 |
| 98 // Invoked when the user uses Shift+F4/F4 to toggle the window |
| 99 // fullscreen state. |
| 100 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { |
| 101 bool is_fullscreen = window_state->IsFullscreen(); |
| 102 |
| 103 // Windows which cannot be maximized should not be fullscreened. |
| 104 if (!is_fullscreen && !window_state->CanMaximize()) |
| 105 return true; |
| 106 |
| 107 Browser* browser = chrome::FindBrowserWithWindow(window_state->window()); |
| 108 CHECK(browser); |
| 109 if (is_fullscreen) { |
| 110 chrome::ToggleFullscreenMode(browser); |
| 111 return true; |
| 112 } |
| 113 // AppNonClientFrameViewAsh shows only the window controls and no other |
| 114 // window decorations which is pretty close to fullscreen. Put v1 apps |
| 115 // into maximized mode instead of fullscreen to avoid showing the ugly |
| 116 // fullscreen exit bubble. |
| 117 if (browser->is_app() && browser->app_type() != Browser::APP_TYPE_CHILD) |
| 118 window_state->ToggleMaximized(); |
| 119 else |
| 120 chrome::ToggleFullscreenMode(browser); |
| 121 return true; |
| 122 } |
| 123 private: |
| 124 DISALLOW_COPY_AND_ASSIGN(FrameWindowStateDelegate); |
| 125 }; |
| 126 |
| 88 } // namespace | 127 } // namespace |
| 89 | 128 |
| 90 // Observer to detect when the browser frame widget closes so we can clean | 129 // Observer to detect when the browser frame widget closes so we can clean |
| 91 // up our ControlView. Because we can be closed via a keyboard shortcut we | 130 // up our ControlView. Because we can be closed via a keyboard shortcut we |
| 92 // are not guaranteed to run AppNonClientFrameView's Close() or Restore(). | 131 // are not guaranteed to run AppNonClientFrameView's Close() or Restore(). |
| 93 class AppNonClientFrameViewAsh::FrameObserver : public views::WidgetObserver { | 132 class AppNonClientFrameViewAsh::FrameObserver : public views::WidgetObserver { |
| 94 public: | 133 public: |
| 95 explicit FrameObserver(AppNonClientFrameViewAsh* owner) : owner_(owner) {} | 134 explicit FrameObserver(AppNonClientFrameViewAsh* owner) : owner_(owner) {} |
| 96 virtual ~FrameObserver() {} | 135 virtual ~FrameObserver() {} |
| 97 | 136 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Need to exclude the shadow from the active control area. | 185 // Need to exclude the shadow from the active control area. |
| 147 gfx::Insets hit_test_insets(control_view_->GetInsets()); | 186 gfx::Insets hit_test_insets(control_view_->GetInsets()); |
| 148 if (base::i18n::IsRTL()) { | 187 if (base::i18n::IsRTL()) { |
| 149 hit_test_insets = gfx::Insets(hit_test_insets.top(), | 188 hit_test_insets = gfx::Insets(hit_test_insets.top(), |
| 150 hit_test_insets.right(), | 189 hit_test_insets.right(), |
| 151 hit_test_insets.bottom(), | 190 hit_test_insets.bottom(), |
| 152 hit_test_insets.left()); | 191 hit_test_insets.left()); |
| 153 } | 192 } |
| 154 window->SetHitTestBoundsOverrideOuter(hit_test_insets, hit_test_insets); | 193 window->SetHitTestBoundsOverrideOuter(hit_test_insets, hit_test_insets); |
| 155 | 194 |
| 195 |
| 196 ash::wm::GetWindowState(window)->SetDelegate(new FrameWindowStateDelegate()); |
| 197 |
| 156 gfx::Rect control_bounds = GetControlBounds(); | 198 gfx::Rect control_bounds = GetControlBounds(); |
| 157 window->SetBounds(control_bounds); | 199 window->SetBounds(control_bounds); |
| 158 control_widget_->Show(); | 200 control_widget_->Show(); |
| 159 } | 201 } |
| 160 | 202 |
| 161 AppNonClientFrameViewAsh::~AppNonClientFrameViewAsh() { | 203 AppNonClientFrameViewAsh::~AppNonClientFrameViewAsh() { |
| 162 frame()->RemoveObserver(frame_observer_.get()); | 204 frame()->RemoveObserver(frame_observer_.get()); |
| 163 // This frame view can be replaced (and deleted) if the window is restored | 205 // This frame view can be replaced (and deleted) if the window is restored |
| 164 // via a keyboard shortcut like Alt-[. Ensure we close the control widget. | 206 // via a keyboard shortcut like Alt-[. Ensure we close the control widget. |
| 165 CloseControlWidget(); | 207 CloseControlWidget(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, | 269 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, |
| 228 preferred.width(), preferred.height()); | 270 preferred.width(), preferred.height()); |
| 229 } | 271 } |
| 230 | 272 |
| 231 void AppNonClientFrameViewAsh::CloseControlWidget() { | 273 void AppNonClientFrameViewAsh::CloseControlWidget() { |
| 232 if (control_widget_) { | 274 if (control_widget_) { |
| 233 control_widget_->Close(); | 275 control_widget_->Close(); |
| 234 control_widget_ = NULL; | 276 control_widget_ = NULL; |
| 235 } | 277 } |
| 236 } | 278 } |
| OLD | NEW |