| 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) { |
| 39 DCHECK(delegate_); |
| 41 } | 40 } |
| 42 | 41 |
| 43 ScreenMus::~ScreenMus() { | 42 ScreenMus::~ScreenMus() {} |
| 44 DCHECK_EQ(this, display::Screen::GetScreen()); | |
| 45 display::Screen::SetScreenInstance(nullptr); | |
| 46 } | |
| 47 | 43 |
| 48 void ScreenMus::Init(shell::Connector* connector) { | 44 void ScreenMus::Init(shell::Connector* connector) { |
| 49 display::Screen::SetScreenInstance(this); | |
| 50 | |
| 51 connector->ConnectToInterface("mojo:ui", &display_manager_); | 45 connector->ConnectToInterface("mojo:ui", &display_manager_); |
| 52 | 46 |
| 53 display_manager_->AddObserver( | 47 display_manager_->AddObserver( |
| 54 display_manager_observer_binding_.CreateInterfacePtrAndBind()); | 48 display_manager_observer_binding_.CreateInterfacePtrAndBind()); |
| 55 | 49 |
| 56 // We need the set of displays before we can continue. Wait for it. | 50 // We need the set of displays before we can continue. Wait for it. |
| 57 // | 51 // |
| 58 // TODO(rockot): Do something better here. This should not have to block tasks | 52 // TODO(rockot): Do something better here. This should not have to block tasks |
| 59 // from running on the calling thread. http://crbug.com/594852. | 53 // from running on the calling thread. http://crbug.com/594852. |
| 60 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); | 54 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); |
| 61 | 55 |
| 62 // The WaitForIncomingMethodCall() should have supplied the set of Displays, | 56 // The WaitForIncomingMethodCall() should have supplied the set of Displays, |
| 63 // unless mus is going down, in which case encountered_error() is true, or the | 57 // unless mus is going down, in which case encountered_error() is true, or the |
| 64 // call to WaitForIncomingMethodCall() failed. | 58 // call to WaitForIncomingMethodCall() failed. |
| 65 if (display_list_.displays().empty()) { | 59 if (display_list()->displays().empty()) { |
| 66 DCHECK(display_manager_.encountered_error() || !success); | 60 DCHECK(display_manager_.encountered_error() || !success); |
| 67 // In this case we install a default display and assume the process is | 61 // 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. | 62 // going to exit shortly so that the real value doesn't matter. |
| 69 display_list_.AddDisplay( | 63 display_list()->AddDisplay( |
| 70 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), | 64 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), |
| 71 DisplayList::Type::PRIMARY); | 65 display::DisplayList::Type::PRIMARY); |
| 72 } | 66 } |
| 73 } | 67 } |
| 74 | 68 |
| 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() { | 69 gfx::Point ScreenMus::GetCursorScreenPoint() { |
| 90 if (!delegate_) { | |
| 91 // 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. | |
| 93 NOTIMPLEMENTED(); | |
| 94 return gfx::Point(); | |
| 95 } | |
| 96 | |
| 97 return delegate_->GetCursorScreenPoint(); | 70 return delegate_->GetCursorScreenPoint(); |
| 98 } | 71 } |
| 99 | 72 |
| 100 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) { | 73 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 101 if (!window) | 74 return window && window->IsVisible() && |
| 102 return false; | 75 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 } | 76 } |
| 150 | 77 |
| 151 void ScreenMus::OnDisplays(mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | 78 void ScreenMus::OnDisplays(mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { |
| 152 // This should only be called once from Init() before any observers have been | 79 // This should only be called once from Init() before any observers have been |
| 153 // added. | 80 // added. |
| 154 DCHECK(display_list_.displays().empty()); | 81 DCHECK(display_list()->displays().empty()); |
| 155 for (size_t i = 0; i < ws_displays.size(); ++i) { | 82 for (size_t i = 0; i < ws_displays.size(); ++i) { |
| 156 const bool is_primary = ws_displays[i]->is_primary; | 83 const bool is_primary = ws_displays[i]->is_primary; |
| 157 display_list_.AddDisplay(ws_displays[i]->display, | 84 display_list()->AddDisplay(ws_displays[i]->display, |
| 158 is_primary ? DisplayList::Type::PRIMARY | 85 is_primary |
| 159 : DisplayList::Type::NOT_PRIMARY); | 86 ? display::DisplayList::Type::PRIMARY |
| 87 : display::DisplayList::Type::NOT_PRIMARY); |
| 160 if (is_primary) { | 88 if (is_primary) { |
| 161 // TODO(sky): Make WindowManagerFrameValues per display. | 89 // TODO(sky): Make WindowManagerFrameValues per display. |
| 162 WindowManagerFrameValues frame_values = | 90 WindowManagerFrameValues frame_values = |
| 163 ws_displays[i] | 91 ws_displays[i] |
| 164 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 92 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 165 WindowManagerFrameValues::SetInstance(frame_values); | 93 WindowManagerFrameValues::SetInstance(frame_values); |
| 166 } | 94 } |
| 167 } | 95 } |
| 168 DCHECK(!display_list_.displays().empty()); | 96 DCHECK(!display_list()->displays().empty()); |
| 169 } | 97 } |
| 170 | 98 |
| 171 void ScreenMus::OnDisplaysChanged( | 99 void ScreenMus::OnDisplaysChanged( |
| 172 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | 100 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { |
| 173 for (size_t i = 0; i < ws_displays.size(); ++i) { | 101 for (size_t i = 0; i < ws_displays.size(); ++i) { |
| 174 const bool is_primary = ws_displays[i]->is_primary; | 102 const bool is_primary = ws_displays[i]->is_primary; |
| 175 ProcessDisplayChanged(ws_displays[i]->display, is_primary); | 103 ProcessDisplayChanged(ws_displays[i]->display, is_primary); |
| 176 if (is_primary) { | 104 if (is_primary) { |
| 177 WindowManagerFrameValues frame_values = | 105 WindowManagerFrameValues frame_values = |
| 178 ws_displays[i] | 106 ws_displays[i] |
| 179 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 107 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 180 WindowManagerFrameValues::SetInstance(frame_values); | 108 WindowManagerFrameValues::SetInstance(frame_values); |
| 181 if (delegate_) | 109 delegate_->OnWindowManagerFrameValuesChanged(); |
| 182 delegate_->OnWindowManagerFrameValuesChanged(); | |
| 183 } | 110 } |
| 184 } | 111 } |
| 185 } | 112 } |
| 186 | 113 |
| 187 void ScreenMus::OnDisplayRemoved(int64_t id) { | 114 void ScreenMus::OnDisplayRemoved(int64_t id) { |
| 188 display_list_.RemoveDisplay(id); | 115 display_list()->RemoveDisplay(id); |
| 189 } | 116 } |
| 190 | 117 |
| 191 } // namespace views | 118 } // namespace views |
| OLD | NEW |