Chromium Code Reviews| 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 void PlatformWindowMus::Hide() { | |
| 50 mus_window_->SetVisible(false); | |
| 51 } | |
| 52 void PlatformWindowMus::Close() { | |
| 53 NOTIMPLEMENTED(); | |
| 54 } | |
| 55 | |
| 56 void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) { | |
| 57 mus_window_->SetBounds(bounds); | |
| 58 } | |
| 59 gfx::Rect PlatformWindowMus::GetBounds() { | |
|
sky
2015/11/10 19:03:00
nit: use newlines!
sadrul
2015/11/10 20:59:45
Done.
| |
| 60 return mus_window_->bounds(); | |
| 61 } | |
| 62 void PlatformWindowMus::SetTitle(const base::string16& title) { | |
| 63 NOTIMPLEMENTED(); | |
| 64 } | |
| 65 void PlatformWindowMus::SetCapture() { | |
| 66 NOTIMPLEMENTED(); | |
| 67 } | |
| 68 void PlatformWindowMus::ReleaseCapture() { | |
| 69 NOTIMPLEMENTED(); | |
| 70 } | |
| 71 void PlatformWindowMus::ToggleFullscreen() { | |
| 72 NOTIMPLEMENTED(); | |
| 73 } | |
| 74 void PlatformWindowMus::Maximize() { | |
| 75 SetShowState(mus::mojom::SHOW_STATE_MAXIMIZED); | |
| 76 } | |
| 77 void PlatformWindowMus::Minimize() { | |
| 78 SetShowState(mus::mojom::SHOW_STATE_MINIMIZED); | |
| 79 } | |
| 80 void PlatformWindowMus::Restore() { | |
| 81 SetShowState(mus::mojom::SHOW_STATE_RESTORED); | |
| 82 } | |
| 83 void PlatformWindowMus::SetCursor(ui::PlatformCursor cursor) { | |
| 84 NOTIMPLEMENTED(); | |
| 85 } | |
| 86 void PlatformWindowMus::MoveCursorTo(const gfx::Point& location) { | |
| 87 NOTIMPLEMENTED(); | |
| 88 } | |
| 89 void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) { | |
| 90 NOTIMPLEMENTED(); | |
| 91 } | |
| 92 ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() { | |
| 93 return nullptr; | |
| 94 } | |
| 95 | |
| 96 void PlatformWindowMus::OnWindowDestroyed(mus::Window* window) { | |
| 97 DCHECK_EQ(mus_window_, window); | |
| 98 delegate_->OnClosed(); | |
| 99 mus_window_ = nullptr; | |
| 100 } | |
| 101 | |
| 102 void PlatformWindowMus::OnWindowBoundsChanged(mus::Window* window, | |
| 103 const gfx::Rect& old_bounds, | |
| 104 const gfx::Rect& new_bounds) { | |
| 105 delegate_->OnBoundsChanged(new_bounds); | |
| 106 } | |
| 107 | |
| 108 void PlatformWindowMus::OnWindowFocusChanged(mus::Window* gained_focus, | |
| 109 mus::Window* lost_focus) { | |
| 110 if (gained_focus == mus_window_) | |
| 111 delegate_->OnActivationChanged(true); | |
| 112 else if (lost_focus == mus_window_) | |
| 113 delegate_->OnActivationChanged(false); | |
| 114 } | |
| 115 | |
| 116 void PlatformWindowMus::OnWindowInputEvent(mus::Window* view, | |
| 117 const mus::mojom::EventPtr& event) { | |
| 118 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>()); | |
| 119 delegate_->DispatchEvent(ui_event.get()); | |
| 120 } | |
| 121 | |
| 122 void PlatformWindowMus::OnWindowSharedPropertyChanged( | |
| 123 mus::Window* window, | |
| 124 const std::string& name, | |
| 125 const std::vector<uint8_t>* old_data, | |
| 126 const std::vector<uint8_t>* new_data) { | |
| 127 if (name != mus::mojom::WindowManager::kShowState_Property) | |
| 128 return; | |
| 129 mus::mojom::ShowState show_state = | |
| 130 static_cast<mus::mojom::ShowState>(window->GetSharedProperty<int32_t>( | |
| 131 mus::mojom::WindowManager::kShowState_Property)); | |
| 132 if (show_state == show_state_) | |
| 133 return; | |
| 134 show_state_ = show_state; | |
| 135 ui::PlatformWindowState state = ui::PLATFORM_WINDOW_STATE_UNKNOWN; | |
| 136 switch (show_state_) { | |
| 137 case mus::mojom::SHOW_STATE_MINIMIZED: | |
| 138 state = ui::PLATFORM_WINDOW_STATE_MINIMIZED; | |
| 139 break; | |
| 140 case mus::mojom::SHOW_STATE_MAXIMIZED: | |
| 141 state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED; | |
| 142 break; | |
| 143 case mus::mojom::SHOW_STATE_RESTORED: | |
| 144 state = ui::PLATFORM_WINDOW_STATE_NORMAL; | |
| 145 break; | |
| 146 case mus::mojom::SHOW_STATE_IMMERSIVE: | |
| 147 case mus::mojom::SHOW_STATE_PRESENTATION: | |
| 148 // This may not be sufficient. | |
| 149 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; | |
| 150 break; | |
| 151 } | |
| 152 delegate_->OnWindowStateChanged(state); | |
| 153 } | |
| 154 | |
| 155 } // namespace views | |
| OLD | NEW |