| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/desktop/desktop_window_view.h" | 5 #include "views/desktop/desktop_window_view.h" |
| 6 | 6 |
| 7 #include "ui/gfx/canvas.h" | 7 #include "ui/gfx/canvas.h" |
| 8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
| 9 #include "views/desktop/desktop_background.h" | 9 #include "views/desktop/desktop_background.h" |
| 10 #include "views/desktop/desktop_window_root_view.h" | |
| 11 #include "views/desktop/desktop_window_manager.h" | 10 #include "views/desktop/desktop_window_manager.h" |
| 12 #include "views/layer_property_setter.h" | 11 #include "views/layer_property_setter.h" |
| 13 #include "views/widget/native_widget_view.h" | 12 #include "views/widget/native_widget_view.h" |
| 14 #include "views/widget/native_widget_views.h" | 13 #include "views/widget/native_widget_views.h" |
| 15 #include "views/widget/widget.h" | 14 #include "views/widget/widget.h" |
| 16 #include "views/window/native_frame_view.h" | 15 #include "views/window/native_frame_view.h" |
| 17 | 16 |
| 18 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
| 19 #include "views/widget/native_widget_aura.h" | 18 #include "views/widget/native_widget_aura.h" |
| 20 #elif defined(OS_WIN) | 19 #elif defined(OS_WIN) |
| 21 #include "views/widget/native_widget_win.h" | 20 #include "views/widget/native_widget_win.h" |
| 22 #elif defined(TOOLKIT_USES_GTK) | 21 #elif defined(TOOLKIT_USES_GTK) |
| 23 #include "views/widget/native_widget_gtk.h" | 22 #include "views/widget/native_widget_gtk.h" |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 namespace views { | 25 namespace views { |
| 27 namespace desktop { | 26 namespace desktop { |
| 28 | 27 |
| 29 // The Widget that hosts the DesktopWindowView. Subclasses Widget to override | 28 // The Widget that hosts the DesktopWindowView. Subclasses Widget to override |
| 30 // CreateRootView() so that the DesktopWindowRootView can be supplied instead | 29 // CreateRootView() so that the DesktopWindowRootView can be supplied instead |
| 31 // for custom event filtering. | 30 // for custom event filtering. |
| 32 class DesktopWindow : public Widget { | 31 class DesktopWindow : public Widget { |
| 33 public: | 32 public: |
| 34 explicit DesktopWindow(DesktopWindowView* desktop_window_view) | 33 explicit DesktopWindow(DesktopWindowView* desktop_window_view) |
| 35 : desktop_window_view_(desktop_window_view) {} | 34 : desktop_window_view_(desktop_window_view) {} |
| 36 virtual ~DesktopWindow() {} | 35 virtual ~DesktopWindow() {} |
| 37 | 36 |
| 38 private: | 37 private: |
| 39 // Overridden from Widget: | 38 // Overridden from Widget: |
| 40 virtual internal::RootView* CreateRootView() OVERRIDE { | |
| 41 return new DesktopWindowRootView(desktop_window_view_, this); | |
| 42 } | |
| 43 | |
| 44 virtual bool OnKeyEvent(const KeyEvent& event) OVERRIDE { | 39 virtual bool OnKeyEvent(const KeyEvent& event) OVERRIDE { |
| 45 NativeWidgetViews* native_widget = | 40 return WindowManager::Get()->HandleKeyEvent(this, event); |
| 46 desktop_window_view_->active_native_widget(); | |
| 47 return native_widget ? native_widget->OnKeyEvent(event) : false; | |
| 48 } | 41 } |
| 49 | 42 |
| 50 virtual bool OnMouseEvent(const MouseEvent& event) { | 43 virtual bool OnMouseEvent(const MouseEvent& event) { |
| 51 if (event.type() == ui::ET_MOUSEWHEEL) { | |
| 52 NativeWidgetViews* native_widget = | |
| 53 desktop_window_view_->active_native_widget(); | |
| 54 if (native_widget) | |
| 55 return native_widget->delegate()->OnMouseEvent(event); | |
| 56 } | |
| 57 return WindowManager::Get()->HandleMouseEvent(this, event) || | 44 return WindowManager::Get()->HandleMouseEvent(this, event) || |
| 58 Widget::OnMouseEvent(event); | 45 Widget::OnMouseEvent(event); |
| 59 } | 46 } |
| 60 | 47 |
| 61 DesktopWindowView* desktop_window_view_; | 48 DesktopWindowView* desktop_window_view_; |
| 62 | 49 |
| 63 DISALLOW_COPY_AND_ASSIGN(DesktopWindow); | 50 DISALLOW_COPY_AND_ASSIGN(DesktopWindow); |
| 64 }; | 51 }; |
| 65 | 52 |
| 66 class TestWindowContentView : public WidgetDelegateView { | 53 class TestWindowContentView : public WidgetDelegateView { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 DISALLOW_COPY_AND_ASSIGN(TestWindowContentView); | 89 DISALLOW_COPY_AND_ASSIGN(TestWindowContentView); |
| 103 }; | 90 }; |
| 104 | 91 |
| 105 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
| 106 // DesktopWindowView, public: | 93 // DesktopWindowView, public: |
| 107 | 94 |
| 108 // static | 95 // static |
| 109 DesktopWindowView* DesktopWindowView::desktop_window_view = NULL; | 96 DesktopWindowView* DesktopWindowView::desktop_window_view = NULL; |
| 110 | 97 |
| 111 DesktopWindowView::DesktopWindowView(DesktopType type) | 98 DesktopWindowView::DesktopWindowView(DesktopType type) |
| 112 : active_native_widget_(NULL), | 99 : type_(type) { |
| 113 type_(type) { | |
| 114 switch (type_) { | 100 switch (type_) { |
| 115 case DESKTOP_DEFAULT: | 101 case DESKTOP_DEFAULT: |
| 116 case DESKTOP_NETBOOK: | 102 case DESKTOP_NETBOOK: |
| 117 set_background(new DesktopBackground); | 103 set_background(new DesktopBackground); |
| 118 break; | 104 break; |
| 119 case DESKTOP_OTHER: | 105 case DESKTOP_OTHER: |
| 120 set_background(Background::CreateStandardPanelBackground()); | 106 set_background(Background::CreateStandardPanelBackground()); |
| 121 break; | 107 break; |
| 122 } | 108 } |
| 123 } | 109 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 145 params.native_widget = new views::NativeWidgetWin(window); | 131 params.native_widget = new views::NativeWidgetWin(window); |
| 146 #elif defined(TOOLKIT_USES_GTK) | 132 #elif defined(TOOLKIT_USES_GTK) |
| 147 params.native_widget = new views::NativeWidgetGtk(window); | 133 params.native_widget = new views::NativeWidgetGtk(window); |
| 148 params.maximize = true; | 134 params.maximize = true; |
| 149 #endif | 135 #endif |
| 150 params.bounds = gfx::Rect(20, 20, 1920, 1200); | 136 params.bounds = gfx::Rect(20, 20, 1920, 1200); |
| 151 window->Init(params); | 137 window->Init(params); |
| 152 window->Show(); | 138 window->Show(); |
| 153 } | 139 } |
| 154 | 140 |
| 155 void DesktopWindowView::ActivateWidget(Widget* widget) { | |
| 156 if (widget && widget->IsActive()) | |
| 157 return; | |
| 158 | |
| 159 if (widget) { | |
| 160 if (!widget->HasObserver(this)) | |
| 161 widget->AddObserver(this); | |
| 162 widget->Activate(); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 | |
| 167 void DesktopWindowView::CreateTestWindow(const std::wstring& title, | 141 void DesktopWindowView::CreateTestWindow(const std::wstring& title, |
| 168 SkColor color, | 142 SkColor color, |
| 169 gfx::Rect initial_bounds, | 143 gfx::Rect initial_bounds, |
| 170 bool rotate) { | 144 bool rotate) { |
| 171 views::Widget* window = views::Widget::CreateWindowWithBounds( | 145 views::Widget* window = views::Widget::CreateWindowWithBounds( |
| 172 new TestWindowContentView(title, color), | 146 new TestWindowContentView(title, color), |
| 173 initial_bounds); | 147 initial_bounds); |
| 174 window->Show(); | 148 window->Show(); |
| 175 | 149 |
| 176 if (rotate) { | 150 if (rotate) { |
| 177 ui::Transform transform; | 151 ui::Transform transform; |
| 178 transform.SetRotate(90.0f); | 152 transform.SetRotate(90.0f); |
| 179 transform.SetTranslateX(window->GetWindowScreenBounds().width()); | 153 transform.SetTranslateX(window->GetWindowScreenBounds().width()); |
| 180 static_cast<NativeWidgetViews*>(window->native_widget())->GetView()-> | 154 static_cast<NativeWidgetViews*>(window->native_widget())->GetView()-> |
| 181 SetTransform(transform); | 155 SetTransform(transform); |
| 182 } | 156 } |
| 183 static_cast<NativeWidgetViews*>(window->native_widget())->GetView()-> | 157 static_cast<NativeWidgetViews*>(window->native_widget())->GetView()-> |
| 184 SetLayerPropertySetter(LayerPropertySetter::CreateAnimatingSetter()); | 158 SetLayerPropertySetter(LayerPropertySetter::CreateAnimatingSetter()); |
| 185 } | 159 } |
| 186 | 160 |
| 187 //////////////////////////////////////////////////////////////////////////////// | 161 //////////////////////////////////////////////////////////////////////////////// |
| 188 // DesktopWindowView, View overrides: | 162 // DesktopWindowView, View overrides: |
| 189 | 163 |
| 190 void DesktopWindowView::Layout() { | 164 void DesktopWindowView::Layout() { |
| 191 } | 165 } |
| 192 | 166 |
| 193 void DesktopWindowView::ViewHierarchyChanged( | 167 void DesktopWindowView::ViewHierarchyChanged( |
| 194 bool is_add, View* parent, View* child) { | 168 bool is_add, View* parent, View* child) { |
| 195 if (!is_add && | 169 if (child->GetClassName() == internal::NativeWidgetView::kViewClassName) { |
| 196 active_native_widget_ && | 170 Widget* widget = |
| 197 active_native_widget_->GetView() == child) { | 171 static_cast<internal::NativeWidgetView*>(child)->GetAssociatedWidget(); |
| 198 active_native_widget_ = NULL; | 172 if (is_add) |
| 199 } else if (is_add && | 173 WindowManager::Get()->Register(widget); |
| 200 child->GetClassName() == internal::NativeWidgetView::kViewClassName) { | |
| 201 internal::NativeWidgetView* native_widget_view = | |
| 202 static_cast<internal::NativeWidgetView*>(child); | |
| 203 native_widget_view->GetAssociatedWidget()->AddObserver(this); | |
| 204 } | 174 } |
| 205 } | 175 } |
| 206 | 176 |
| 207 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
| 208 // DesktopWindowView, WidgetDelegate implementation: | 178 // DesktopWindowView, WidgetDelegate implementation: |
| 209 | 179 |
| 210 Widget* DesktopWindowView::GetWidget() { | 180 Widget* DesktopWindowView::GetWidget() { |
| 211 return widget_; | 181 return widget_; |
| 212 } | 182 } |
| 213 | 183 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 case DESKTOP_DEFAULT: | 222 case DESKTOP_DEFAULT: |
| 253 case DESKTOP_NETBOOK: | 223 case DESKTOP_NETBOOK: |
| 254 return NULL; | 224 return NULL; |
| 255 | 225 |
| 256 case DESKTOP_OTHER: | 226 case DESKTOP_OTHER: |
| 257 return new NativeFrameView(widget_); | 227 return new NativeFrameView(widget_); |
| 258 } | 228 } |
| 259 return NULL; | 229 return NULL; |
| 260 } | 230 } |
| 261 | 231 |
| 262 void DesktopWindowView::OnWidgetClosing(Widget* widget) { | |
| 263 if (active_native_widget_ && static_cast<internal::NativeWidgetPrivate*> | |
| 264 (active_native_widget_)->GetWidget() == widget) | |
| 265 active_native_widget_ = NULL; | |
| 266 } | |
| 267 | |
| 268 void DesktopWindowView::OnWidgetVisibilityChanged(Widget* widget, | |
| 269 bool visible) { | |
| 270 } | |
| 271 | |
| 272 void DesktopWindowView::OnWidgetActivationChanged(Widget* widget, | |
| 273 bool active) { | |
| 274 if (active) { | |
| 275 if (active_native_widget_) | |
| 276 active_native_widget_->GetWidget()->Deactivate(); | |
| 277 active_native_widget_ = | |
| 278 static_cast<NativeWidgetViews*>(widget->native_widget()); | |
| 279 } else if (widget == active_native_widget_->GetWidget()) { | |
| 280 active_native_widget_ = NULL; | |
| 281 } | |
| 282 } | |
| 283 | |
| 284 } // namespace desktop | 232 } // namespace desktop |
| 285 } // namespace views | 233 } // namespace views |
| OLD | NEW |