OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ui/views/mus/platform_window_mus.h" |
| 6 |
| 7 #include "components/mus/public/cpp/property_type_converters.h" |
| 8 #include "components/mus/public/cpp/window_property.h" |
| 9 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 11 #include "ui/platform_window/platform_window_delegate.h" |
| 12 #include "ui/views/mus/window_manager_connection.h" |
| 13 |
| 14 namespace views { |
| 15 |
| 16 namespace { |
| 17 void WindowManagerCallback(mus::mojom::WindowManagerErrorCode error_code) {} |
| 18 } // namespace |
| 19 |
| 20 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, |
| 21 mus::Window* mus_window) |
| 22 : delegate_(delegate), |
| 23 mus_window_(mus_window), |
| 24 show_state_(mus::mojom::SHOW_STATE_RESTORED) { |
| 25 DCHECK(delegate_); |
| 26 DCHECK(mus_window_); |
| 27 mus_window_->AddObserver(this); |
| 28 |
| 29 delegate_->OnAcceleratedWidgetAvailable( |
| 30 gfx::kNullAcceleratedWidget, |
| 31 mus_window_->viewport_metrics().device_pixel_ratio); |
| 32 } |
| 33 |
| 34 PlatformWindowMus::~PlatformWindowMus() { |
| 35 if (!mus_window_) |
| 36 return; |
| 37 mus_window_->RemoveObserver(this); |
| 38 mus_window_->Destroy(); |
| 39 } |
| 40 |
| 41 void PlatformWindowMus::SetShowState(mus::mojom::ShowState show_state) { |
| 42 WindowManagerConnection::Get()->window_manager()->SetShowState( |
| 43 mus_window_->id(), show_state, base::Bind(&WindowManagerCallback)); |
| 44 } |
| 45 |
| 46 void PlatformWindowMus::Show() { |
| 47 mus_window_->SetVisible(true); |
| 48 } |
| 49 |
| 50 void PlatformWindowMus::Hide() { |
| 51 mus_window_->SetVisible(false); |
| 52 } |
| 53 |
| 54 void PlatformWindowMus::Close() { |
| 55 NOTIMPLEMENTED(); |
| 56 } |
| 57 |
| 58 void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) { |
| 59 mus_window_->SetBounds(bounds); |
| 60 } |
| 61 |
| 62 gfx::Rect PlatformWindowMus::GetBounds() { |
| 63 return mus_window_->bounds(); |
| 64 } |
| 65 |
| 66 void PlatformWindowMus::SetTitle(const base::string16& title) { |
| 67 NOTIMPLEMENTED(); |
| 68 } |
| 69 |
| 70 void PlatformWindowMus::SetCapture() { |
| 71 NOTIMPLEMENTED(); |
| 72 } |
| 73 |
| 74 void PlatformWindowMus::ReleaseCapture() { |
| 75 NOTIMPLEMENTED(); |
| 76 } |
| 77 |
| 78 void PlatformWindowMus::ToggleFullscreen() { |
| 79 NOTIMPLEMENTED(); |
| 80 } |
| 81 |
| 82 void PlatformWindowMus::Maximize() { |
| 83 SetShowState(mus::mojom::SHOW_STATE_MAXIMIZED); |
| 84 } |
| 85 |
| 86 void PlatformWindowMus::Minimize() { |
| 87 SetShowState(mus::mojom::SHOW_STATE_MINIMIZED); |
| 88 } |
| 89 |
| 90 void PlatformWindowMus::Restore() { |
| 91 SetShowState(mus::mojom::SHOW_STATE_RESTORED); |
| 92 } |
| 93 |
| 94 void PlatformWindowMus::SetCursor(ui::PlatformCursor cursor) { |
| 95 NOTIMPLEMENTED(); |
| 96 } |
| 97 |
| 98 void PlatformWindowMus::MoveCursorTo(const gfx::Point& location) { |
| 99 NOTIMPLEMENTED(); |
| 100 } |
| 101 |
| 102 void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) { |
| 103 NOTIMPLEMENTED(); |
| 104 } |
| 105 |
| 106 ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() { |
| 107 return nullptr; |
| 108 } |
| 109 |
| 110 void PlatformWindowMus::OnWindowDestroyed(mus::Window* window) { |
| 111 DCHECK_EQ(mus_window_, window); |
| 112 delegate_->OnClosed(); |
| 113 mus_window_ = nullptr; |
| 114 } |
| 115 |
| 116 void PlatformWindowMus::OnWindowBoundsChanged(mus::Window* window, |
| 117 const gfx::Rect& old_bounds, |
| 118 const gfx::Rect& new_bounds) { |
| 119 delegate_->OnBoundsChanged(new_bounds); |
| 120 } |
| 121 |
| 122 void PlatformWindowMus::OnWindowFocusChanged(mus::Window* gained_focus, |
| 123 mus::Window* lost_focus) { |
| 124 if (gained_focus == mus_window_) |
| 125 delegate_->OnActivationChanged(true); |
| 126 else if (lost_focus == mus_window_) |
| 127 delegate_->OnActivationChanged(false); |
| 128 } |
| 129 |
| 130 void PlatformWindowMus::OnWindowInputEvent(mus::Window* view, |
| 131 const mus::mojom::EventPtr& event) { |
| 132 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>()); |
| 133 delegate_->DispatchEvent(ui_event.get()); |
| 134 } |
| 135 |
| 136 void PlatformWindowMus::OnWindowSharedPropertyChanged( |
| 137 mus::Window* window, |
| 138 const std::string& name, |
| 139 const std::vector<uint8_t>* old_data, |
| 140 const std::vector<uint8_t>* new_data) { |
| 141 if (name != mus::mojom::WindowManager::kShowState_Property) |
| 142 return; |
| 143 mus::mojom::ShowState show_state = |
| 144 static_cast<mus::mojom::ShowState>(window->GetSharedProperty<int32_t>( |
| 145 mus::mojom::WindowManager::kShowState_Property)); |
| 146 if (show_state == show_state_) |
| 147 return; |
| 148 show_state_ = show_state; |
| 149 ui::PlatformWindowState state = ui::PLATFORM_WINDOW_STATE_UNKNOWN; |
| 150 switch (show_state_) { |
| 151 case mus::mojom::SHOW_STATE_MINIMIZED: |
| 152 state = ui::PLATFORM_WINDOW_STATE_MINIMIZED; |
| 153 break; |
| 154 case mus::mojom::SHOW_STATE_MAXIMIZED: |
| 155 state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED; |
| 156 break; |
| 157 case mus::mojom::SHOW_STATE_RESTORED: |
| 158 state = ui::PLATFORM_WINDOW_STATE_NORMAL; |
| 159 break; |
| 160 case mus::mojom::SHOW_STATE_IMMERSIVE: |
| 161 case mus::mojom::SHOW_STATE_PRESENTATION: |
| 162 // This may not be sufficient. |
| 163 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; |
| 164 break; |
| 165 } |
| 166 delegate_->OnWindowStateChanged(state); |
| 167 } |
| 168 |
| 169 } // namespace views |
OLD | NEW |