| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // This has to be before any other includes, else default is picked up. | 5 // This has to be before any other includes, else default is picked up. |
| 6 // See base/logging for details on this. | 6 // See base/logging for details on this. |
| 7 #define NOTIMPLEMENTED_POLICY 5 | 7 #define NOTIMPLEMENTED_POLICY 5 |
| 8 | 8 |
| 9 #include "ui/views/mus/screen_mus.h" | 9 #include "ui/views/mus/screen_mus.h" |
| 10 | 10 |
| 11 #include "services/shell/public/cpp/connection.h" | 11 #include "services/shell/public/cpp/connection.h" |
| 12 #include "services/shell/public/cpp/connector.h" | 12 #include "services/shell/public/cpp/connector.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/display/display_finder.h" | |
| 15 #include "ui/display/display_observer.h" | |
| 16 #include "ui/views/mus/screen_mus_delegate.h" | 14 #include "ui/views/mus/screen_mus_delegate.h" |
| 17 #include "ui/views/mus/window_manager_frame_values.h" | 15 #include "ui/views/mus/window_manager_frame_values.h" |
| 18 | 16 |
| 19 namespace mojo { | 17 namespace mojo { |
| 20 | 18 |
| 21 template <> | 19 template <> |
| 22 struct TypeConverter<views::WindowManagerFrameValues, | 20 struct TypeConverter<views::WindowManagerFrameValues, |
| 23 ui::mojom::FrameDecorationValuesPtr> { | 21 ui::mojom::FrameDecorationValuesPtr> { |
| 24 static views::WindowManagerFrameValues Convert( | 22 static views::WindowManagerFrameValues Convert( |
| 25 const ui::mojom::FrameDecorationValuesPtr& input) { | 23 const ui::mojom::FrameDecorationValuesPtr& input) { |
| 26 views::WindowManagerFrameValues result; | 24 views::WindowManagerFrameValues result; |
| 27 result.normal_insets = input->normal_client_area_insets; | 25 result.normal_insets = input->normal_client_area_insets; |
| 28 result.maximized_insets = input->maximized_client_area_insets; | 26 result.maximized_insets = input->maximized_client_area_insets; |
| 29 result.max_title_bar_button_width = input->max_title_bar_button_width; | 27 result.max_title_bar_button_width = input->max_title_bar_button_width; |
| 30 return result; | 28 return result; |
| 31 } | 29 } |
| 32 }; | 30 }; |
| 33 | 31 |
| 34 } // namespace mojo | 32 } // namespace mojo |
| 35 | 33 |
| 36 namespace views { | 34 namespace views { |
| 37 | 35 |
| 38 ScreenMus::ScreenMus(ScreenMusDelegate* delegate) | 36 ScreenMus::ScreenMus(ScreenMusDelegate* delegate) |
| 39 : delegate_(delegate), | 37 : delegate_(delegate), |
| 40 display_manager_observer_binding_(this) { | 38 display_manager_observer_binding_(this) { |
| 41 } | 39 } |
| 42 | 40 |
| 43 ScreenMus::~ScreenMus() { | 41 ScreenMus::~ScreenMus() {} |
| 44 DCHECK_EQ(this, display::Screen::GetScreen()); | |
| 45 display::Screen::SetScreenInstance(nullptr); | |
| 46 } | |
| 47 | 42 |
| 48 void ScreenMus::Init(shell::Connector* connector) { | 43 void ScreenMus::Init(shell::Connector* connector) { |
| 49 display::Screen::SetScreenInstance(this); | |
| 50 | |
| 51 connector->ConnectToInterface("mojo:ui", &display_manager_); | 44 connector->ConnectToInterface("mojo:ui", &display_manager_); |
| 52 | 45 |
| 53 display_manager_->AddObserver( | 46 display_manager_->AddObserver( |
| 54 display_manager_observer_binding_.CreateInterfacePtrAndBind()); | 47 display_manager_observer_binding_.CreateInterfacePtrAndBind()); |
| 55 | 48 |
| 56 // We need the set of displays before we can continue. Wait for it. | 49 // We need the set of displays before we can continue. Wait for it. |
| 57 // | 50 // |
| 58 // TODO(rockot): Do something better here. This should not have to block tasks | 51 // TODO(rockot): Do something better here. This should not have to block tasks |
| 59 // from running on the calling thread. http://crbug.com/594852. | 52 // from running on the calling thread. http://crbug.com/594852. |
| 60 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); | 53 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); |
| 61 | 54 |
| 62 // The WaitForIncomingMethodCall() should have supplied the set of Displays, | 55 // The WaitForIncomingMethodCall() should have supplied the set of Displays, |
| 63 // unless mus is going down, in which case encountered_error() is true, or the | 56 // unless mus is going down, in which case encountered_error() is true, or the |
| 64 // call to WaitForIncomingMethodCall() failed. | 57 // call to WaitForIncomingMethodCall() failed. |
| 65 if (display_list_.displays().empty()) { | 58 if (display_list()->displays().empty()) { |
| 66 DCHECK(display_manager_.encountered_error() || !success); | 59 DCHECK(display_manager_.encountered_error() || !success); |
| 67 // In this case we install a default display and assume the process is | 60 // In this case we install a default display and assume the process is |
| 68 // going to exit shortly so that the real value doesn't matter. | 61 // going to exit shortly so that the real value doesn't matter. |
| 69 display_list_.AddDisplay( | 62 display_list()->AddDisplay( |
| 70 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), | 63 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), |
| 71 DisplayList::Type::PRIMARY); | 64 display::DisplayList::Type::PRIMARY); |
| 72 } | 65 } |
| 73 } | 66 } |
| 74 | 67 |
| 75 void ScreenMus::ProcessDisplayChanged(const display::Display& changed_display, | |
| 76 bool is_primary) { | |
| 77 if (display_list_.FindDisplayById(changed_display.id()) == | |
| 78 display_list_.displays().end()) { | |
| 79 display_list_.AddDisplay(changed_display, | |
| 80 is_primary ? DisplayList::Type::PRIMARY | |
| 81 : DisplayList::Type::NOT_PRIMARY); | |
| 82 return; | |
| 83 } | |
| 84 display_list_.UpdateDisplay( | |
| 85 changed_display, | |
| 86 is_primary ? DisplayList::Type::PRIMARY : DisplayList::Type::NOT_PRIMARY); | |
| 87 } | |
| 88 | |
| 89 gfx::Point ScreenMus::GetCursorScreenPoint() { | 68 gfx::Point ScreenMus::GetCursorScreenPoint() { |
| 90 if (!delegate_) { | 69 if (!delegate_) { |
| 91 // TODO(erg): If we need the cursor point in the window manager, we'll need | 70 // TODO(erg): If we need the cursor point in the window manager, we'll need |
| 92 // to make |delegate_| required. It only recently changed to be optional. | 71 // to make |delegate_| required. It only recently changed to be optional. |
| 93 NOTIMPLEMENTED(); | 72 NOTIMPLEMENTED(); |
| 94 return gfx::Point(); | 73 return gfx::Point(); |
| 95 } | 74 } |
| 96 | 75 |
| 97 return delegate_->GetCursorScreenPoint(); | 76 return delegate_->GetCursorScreenPoint(); |
| 98 } | 77 } |
| 99 | 78 |
| 100 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) { | 79 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 101 if (!window) | 80 return window && window->IsVisible() && |
| 102 return false; | 81 window->GetBoundsInScreen().Contains(GetCursorScreenPoint()); |
| 103 | |
| 104 return window->IsVisible() && | |
| 105 window->GetBoundsInScreen().Contains(GetCursorScreenPoint()); | |
| 106 } | |
| 107 | |
| 108 gfx::NativeWindow ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) { | |
| 109 NOTIMPLEMENTED(); | |
| 110 return nullptr; | |
| 111 } | |
| 112 | |
| 113 display::Display ScreenMus::GetPrimaryDisplay() const { | |
| 114 return *display_list_.GetPrimaryDisplayIterator(); | |
| 115 } | |
| 116 | |
| 117 display::Display ScreenMus::GetDisplayNearestWindow( | |
| 118 gfx::NativeView view) const { | |
| 119 NOTIMPLEMENTED(); | |
| 120 return *display_list_.GetPrimaryDisplayIterator(); | |
| 121 } | |
| 122 | |
| 123 display::Display ScreenMus::GetDisplayNearestPoint( | |
| 124 const gfx::Point& point) const { | |
| 125 return *display::FindDisplayNearestPoint(display_list_.displays(), point); | |
| 126 } | |
| 127 | |
| 128 int ScreenMus::GetNumDisplays() const { | |
| 129 return static_cast<int>(display_list_.displays().size()); | |
| 130 } | |
| 131 | |
| 132 std::vector<display::Display> ScreenMus::GetAllDisplays() const { | |
| 133 return display_list_.displays(); | |
| 134 } | |
| 135 | |
| 136 display::Display ScreenMus::GetDisplayMatching( | |
| 137 const gfx::Rect& match_rect) const { | |
| 138 const display::Display* match = display::FindDisplayWithBiggestIntersection( | |
| 139 display_list_.displays(), match_rect); | |
| 140 return match ? *match : GetPrimaryDisplay(); | |
| 141 } | |
| 142 | |
| 143 void ScreenMus::AddObserver(display::DisplayObserver* observer) { | |
| 144 display_list_.AddObserver(observer); | |
| 145 } | |
| 146 | |
| 147 void ScreenMus::RemoveObserver(display::DisplayObserver* observer) { | |
| 148 display_list_.RemoveObserver(observer); | |
| 149 } | 82 } |
| 150 | 83 |
| 151 void ScreenMus::OnDisplays(mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | 84 void ScreenMus::OnDisplays(mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { |
| 152 // This should only be called once from Init() before any observers have been | 85 // This should only be called once from Init() before any observers have been |
| 153 // added. | 86 // added. |
| 154 DCHECK(display_list_.displays().empty()); | 87 DCHECK(display_list()->displays().empty()); |
| 155 for (size_t i = 0; i < ws_displays.size(); ++i) { | 88 for (size_t i = 0; i < ws_displays.size(); ++i) { |
| 156 const bool is_primary = ws_displays[i]->is_primary; | 89 const bool is_primary = ws_displays[i]->is_primary; |
| 157 display_list_.AddDisplay(ws_displays[i]->display, | 90 display_list()->AddDisplay(ws_displays[i]->display, |
| 158 is_primary ? DisplayList::Type::PRIMARY | 91 is_primary |
| 159 : DisplayList::Type::NOT_PRIMARY); | 92 ? display::DisplayList::Type::PRIMARY |
| 93 : display::DisplayList::Type::NOT_PRIMARY); |
| 160 if (is_primary) { | 94 if (is_primary) { |
| 161 // TODO(sky): Make WindowManagerFrameValues per display. | 95 // TODO(sky): Make WindowManagerFrameValues per display. |
| 162 WindowManagerFrameValues frame_values = | 96 WindowManagerFrameValues frame_values = |
| 163 ws_displays[i] | 97 ws_displays[i] |
| 164 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 98 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 165 WindowManagerFrameValues::SetInstance(frame_values); | 99 WindowManagerFrameValues::SetInstance(frame_values); |
| 166 } | 100 } |
| 167 } | 101 } |
| 168 DCHECK(!display_list_.displays().empty()); | 102 DCHECK(!display_list()->displays().empty()); |
| 169 } | 103 } |
| 170 | 104 |
| 171 void ScreenMus::OnDisplaysChanged( | 105 void ScreenMus::OnDisplaysChanged( |
| 172 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | 106 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { |
| 173 for (size_t i = 0; i < ws_displays.size(); ++i) { | 107 for (size_t i = 0; i < ws_displays.size(); ++i) { |
| 174 const bool is_primary = ws_displays[i]->is_primary; | 108 const bool is_primary = ws_displays[i]->is_primary; |
| 175 ProcessDisplayChanged(ws_displays[i]->display, is_primary); | 109 ProcessDisplayChanged(ws_displays[i]->display, is_primary); |
| 176 if (is_primary) { | 110 if (is_primary) { |
| 177 WindowManagerFrameValues frame_values = | 111 WindowManagerFrameValues frame_values = |
| 178 ws_displays[i] | 112 ws_displays[i] |
| 179 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 113 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 180 WindowManagerFrameValues::SetInstance(frame_values); | 114 WindowManagerFrameValues::SetInstance(frame_values); |
| 181 if (delegate_) | 115 if (delegate_) |
| 182 delegate_->OnWindowManagerFrameValuesChanged(); | 116 delegate_->OnWindowManagerFrameValuesChanged(); |
| 183 } | 117 } |
| 184 } | 118 } |
| 185 } | 119 } |
| 186 | 120 |
| 187 void ScreenMus::OnDisplayRemoved(int64_t id) { | 121 void ScreenMus::OnDisplayRemoved(int64_t id) { |
| 188 display_list_.RemoveDisplay(id); | 122 display_list()->RemoveDisplay(id); |
| 189 } | 123 } |
| 190 | 124 |
| 191 } // namespace views | 125 } // namespace views |
| OLD | NEW |