Index: ash/mus/wm/non_client_frame_controller.cc |
diff --git a/ash/mus/wm/non_client_frame_controller.cc b/ash/mus/wm/non_client_frame_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed0eb8afa582ea18662c5ca8263d38752edca9a6 |
--- /dev/null |
+++ b/ash/mus/wm/non_client_frame_controller.cc |
@@ -0,0 +1,185 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/mus/wm/non_client_frame_controller.h" |
+ |
+#include <stdint.h> |
+ |
+#include "base/macros.h" |
+#include "components/mus/public/cpp/property_type_converters.h" |
+#include "components/mus/public/cpp/window.h" |
+#include "components/mus/public/cpp/window_property.h" |
+#include "components/mus/public/interfaces/window_manager.mojom.h" |
+#include "components/mus/public/interfaces/window_tree_host.mojom.h" |
+#include "mojo/converters/geometry/geometry_type_converters.h" |
+#include "ui/aura/layout_manager.h" |
+#include "ui/aura/window.h" |
+#include "ui/aura/window_tree_host.h" |
+#include "ui/compositor/layer.h" |
+#include "ui/views/mus/native_widget_mus.h" |
+#include "ui/views/mus/platform_window_mus.h" |
+#include "ui/views/widget/native_widget_aura.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/widget/widget_observer.h" |
+ |
+namespace ash { |
+namespace muswm { |
+namespace { |
+ |
+void SatisfyCallback(cc::SurfaceSequence sequence) { |
+ // TODO(fsamuel): Implement this. |
+} |
+ |
+// See surface_layer.h for a description of this callback. |
+void RequireCallback(cc::SurfaceId surface_id, cc::SurfaceSequence sequence) { |
+ // TODO(fsamuel): Implement this. |
+} |
+ |
+const int kCaptionHeight = 33; |
+ |
+class NSync : public views::WidgetObserver, public ui::PlatformWindowDelegate { |
+ public: |
+ NSync(views::Widget* widget, mojo::Shell* shell, mus::Window* window) |
+ : widget_(widget), |
+ platform_window_(new views::PlatformWindowMus(this, shell, window)), |
+ mus_window_(window) { |
+ widget_->AddObserver(this); |
+ CreateLayer(); |
+ } |
+ |
+ ~NSync() override { |
+ if (widget_) |
+ widget_->RemoveObserver(this); |
+ } |
+ |
+ private: |
+ void CreateLayer() { |
+ DCHECK(widget_); |
+ layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
+ UpdateLayerSize(); |
+ layer_->SetVisible(true); |
+ widget_->GetNativeWindow()->layer()->Add(layer_.get()); |
+ } |
+ |
+ void UpdateLayerSize() { |
+ gfx::Rect bounds(platform_window_->GetBounds()); |
+ layer_->SetBounds(gfx::Rect(gfx::Point(0, kCaptionHeight), bounds.size())); |
+ layer_->SetShowSurface(static_cast<cc::SurfaceId>(mus_window_->id()), |
+ base::Bind(&SatisfyCallback), |
+ base::Bind(&RequireCallback), bounds.size(), |
+ 1.f, // XXX(sad): |
+ bounds.size()); |
+ } |
+ |
+ // views::WidgetObserver: |
+ void OnWidgetDestroying(views::Widget* widget) override { |
+ widget_->RemoveObserver(this); |
+ widget_ = nullptr; |
+ mus_window_->RequestClose(); |
+ } |
+ |
+ void OnWidgetBoundsChanged(views::Widget* widget, |
+ const gfx::Rect& bounds) override { |
+ gfx::Rect newbounds = bounds; |
+ newbounds.set_height(bounds.height() - kCaptionHeight); |
+ platform_window_->SetBounds(newbounds); |
+ UpdateLayerSize(); |
+ } |
+ |
+ // ui::PlatformWindowDelegate: |
+ void OnBoundsChanged(const gfx::Rect& new_bounds) override {} |
+ void OnDamageRect(const gfx::Rect& damaged_region) override {} |
+ void DispatchEvent(ui::Event* event) override {} |
+ void OnCloseRequest() override {} |
+ void OnClosed() override { delete this; } |
+ void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} |
+ void OnLostCapture() override {} |
+ void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, |
+ float device_pixel_ratio) override {} |
+ void OnAcceleratedWidgetDestroyed() override {} |
+ void OnActivationChanged(bool active) override {} |
+ |
+ views::Widget* widget_; |
+ scoped_ptr<views::PlatformWindowMus> platform_window_; |
+ scoped_ptr<ui::Layer> layer_; |
+ mus::Window* mus_window_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NSync); |
+}; |
+ |
+} // namespace |
+ |
+NonClientFrameController::NonClientFrameController( |
+ mojo::Shell* shell, |
+ mus::Window* window, |
+ mus::mojom::WindowTreeHost* window_tree_host, |
+ aura::Window* aura_root) |
+ : widget_(new views::Widget), |
+ window_(window), |
+ mus_window_tree_host_(window_tree_host) { |
+ window_->AddObserver(this); |
+ |
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
+ params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; |
+ params.delegate = this; |
+ params.native_widget = new views::NativeWidgetAura(widget_); |
+ params.context = aura_root; |
+ params.bounds = window_->bounds(); |
+ widget_->Init(params); |
+ widget_->Show(); |
+ widget_->GetNativeWindow()->SetName(__PRETTY_FUNCTION__); |
+ |
+ new NSync(widget_, shell, window_); |
+} |
+ |
+NonClientFrameController::~NonClientFrameController() { |
+ if (window_) |
+ window_->RemoveObserver(this); |
+} |
+ |
+base::string16 NonClientFrameController::GetWindowTitle() const { |
+ if (!window_ || |
+ !window_->HasSharedProperty( |
+ mus::mojom::WindowManager::kWindowTitle_Property)) { |
+ return base::string16(); |
+ } |
+ |
+ return window_->GetSharedProperty<base::string16>( |
+ mus::mojom::WindowManager::kWindowTitle_Property); |
+} |
+ |
+views::View* NonClientFrameController::GetContentsView() { |
+ return this; |
+} |
+ |
+bool NonClientFrameController::CanResize() const { |
+ return true; |
+} |
+ |
+bool NonClientFrameController::CanMaximize() const { |
+ return true; |
+} |
+ |
+bool NonClientFrameController::CanMinimize() const { |
+ return true; |
+} |
+ |
+void NonClientFrameController::OnWindowSharedPropertyChanged( |
+ mus::Window* window, |
+ const std::string& name, |
+ const std::vector<uint8_t>* old_data, |
+ const std::vector<uint8_t>* new_data) { |
+ if (name == mus::mojom::WindowManager::kResizeBehavior_Property) |
+ widget_->OnSizeConstraintsChanged(); |
+ else if (name == mus::mojom::WindowManager::kWindowTitle_Property) |
+ widget_->UpdateWindowTitle(); |
+} |
+ |
+void NonClientFrameController::OnWindowDestroyed(mus::Window* window) { |
+ window_->RemoveObserver(this); |
+ window_ = nullptr; |
+} |
+ |
+} // namespace muswm |
+} // namespace ash |