| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 result.maximized_insets = input->maximized_client_area_insets; | 27 result.maximized_insets = input->maximized_client_area_insets; |
| 28 result.max_title_bar_button_width = input->max_title_bar_button_width; | 28 result.max_title_bar_button_width = input->max_title_bar_button_width; |
| 29 return result; | 29 return result; |
| 30 } | 30 } |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 } // namespace mojo | 33 } // namespace mojo |
| 34 | 34 |
| 35 namespace views { | 35 namespace views { |
| 36 | 36 |
| 37 using Type = display::DisplayList::Type; |
| 38 |
| 37 ScreenMus::ScreenMus(ScreenMusDelegate* delegate) | 39 ScreenMus::ScreenMus(ScreenMusDelegate* delegate) |
| 38 : delegate_(delegate), | 40 : delegate_(delegate), display_manager_observer_binding_(this) {} |
| 39 display_manager_observer_binding_(this) { | |
| 40 } | |
| 41 | 41 |
| 42 ScreenMus::~ScreenMus() {} | 42 ScreenMus::~ScreenMus() {} |
| 43 | 43 |
| 44 void ScreenMus::Init(service_manager::Connector* connector) { | 44 void ScreenMus::Init(service_manager::Connector* connector) { |
| 45 connector->ConnectToInterface("service:ui", &display_manager_); | 45 connector->ConnectToInterface("service:ui", &display_manager_); |
| 46 | 46 |
| 47 display_manager_->AddObserver( | 47 display_manager_->AddObserver( |
| 48 display_manager_observer_binding_.CreateInterfacePtrAndBind()); | 48 display_manager_observer_binding_.CreateInterfacePtrAndBind()); |
| 49 | 49 |
| 50 // 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. |
| 51 // | 51 // |
| 52 // 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 |
| 53 // from running on the calling thread. http://crbug.com/594852. | 53 // from running on the calling thread. http://crbug.com/594852. |
| 54 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); | 54 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); |
| 55 | 55 |
| 56 // The WaitForIncomingMethodCall() should have supplied the set of Displays, | 56 // The WaitForIncomingMethodCall() should have supplied the set of Displays, |
| 57 // 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 |
| 58 // call to WaitForIncomingMethodCall() failed. | 58 // call to WaitForIncomingMethodCall() failed. |
| 59 if (display_list()->displays().empty()) { | 59 if (display_list()->displays().empty()) { |
| 60 DCHECK(display_manager_.encountered_error() || !success); | 60 DCHECK(display_manager_.encountered_error() || !success); |
| 61 // 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 |
| 62 // 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. |
| 63 display_list()->AddDisplay( | 63 display_list()->AddDisplay( |
| 64 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), | 64 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), Type::PRIMARY); |
| 65 display::DisplayList::Type::PRIMARY); | |
| 66 } | 65 } |
| 67 } | 66 } |
| 68 | 67 |
| 69 gfx::Point ScreenMus::GetCursorScreenPoint() { | 68 gfx::Point ScreenMus::GetCursorScreenPoint() { |
| 70 if (!delegate_) { | 69 if (!delegate_) { |
| 71 // 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 |
| 72 // to make |delegate_| required. It only recently changed to be optional. | 71 // to make |delegate_| required. It only recently changed to be optional. |
| 73 NOTIMPLEMENTED(); | 72 NOTIMPLEMENTED(); |
| 74 return gfx::Point(); | 73 return gfx::Point(); |
| 75 } | 74 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 88 if (ui_window) { | 87 if (ui_window) { |
| 89 NativeWidgetMus* nw_mus = NativeWidgetMus::GetForWindow(ui_window); | 88 NativeWidgetMus* nw_mus = NativeWidgetMus::GetForWindow(ui_window); |
| 90 if (nw_mus) { | 89 if (nw_mus) { |
| 91 aura_window = | 90 aura_window = |
| 92 static_cast<internal::NativeWidgetPrivate*>(nw_mus)->GetNativeView(); | 91 static_cast<internal::NativeWidgetPrivate*>(nw_mus)->GetNativeView(); |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 return aura_window; | 94 return aura_window; |
| 96 } | 95 } |
| 97 | 96 |
| 98 void ScreenMus::OnDisplays(mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | 97 void ScreenMus::OnDisplays(mojo::Array<ui::mojom::WsDisplayPtr> ws_displays, |
| 99 // This should only be called once from Init() before any observers have been | 98 int64_t primary_display_id, |
| 100 // added. | 99 int64_t internal_display_id) { |
| 100 // This should only be called once when ScreenMus is added as an observer. |
| 101 DCHECK(display_list()->displays().empty()); | 101 DCHECK(display_list()->displays().empty()); |
| 102 |
| 102 for (size_t i = 0; i < ws_displays.size(); ++i) { | 103 for (size_t i = 0; i < ws_displays.size(); ++i) { |
| 103 const bool is_primary = ws_displays[i]->is_primary; | 104 const display::Display& display = ws_displays[i]->display; |
| 104 display_list()->AddDisplay(ws_displays[i]->display, | 105 const bool is_primary = display.id() == primary_display_id; |
| 105 is_primary | 106 display_list()->AddDisplay(display, |
| 106 ? display::DisplayList::Type::PRIMARY | 107 is_primary ? Type::PRIMARY : Type::NOT_PRIMARY); |
| 107 : display::DisplayList::Type::NOT_PRIMARY); | |
| 108 if (is_primary) { | 108 if (is_primary) { |
| 109 // TODO(sky): Make WindowManagerFrameValues per display. | 109 // TODO(sky): Make WindowManagerFrameValues per display. |
| 110 WindowManagerFrameValues frame_values = | 110 WindowManagerFrameValues frame_values = |
| 111 ws_displays[i] | 111 ws_displays[i] |
| 112 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 112 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 113 WindowManagerFrameValues::SetInstance(frame_values); | 113 WindowManagerFrameValues::SetInstance(frame_values); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 |
| 117 DCHECK(display_list()->GetPrimaryDisplayIterator() != |
| 118 display_list()->displays().end()); |
| 119 |
| 120 if (internal_display_id != display::Display::kInvalidDisplayID) |
| 121 display::Display::SetInternalDisplayId(internal_display_id); |
| 122 |
| 116 DCHECK(!display_list()->displays().empty()); | 123 DCHECK(!display_list()->displays().empty()); |
| 117 } | 124 } |
| 118 | 125 |
| 119 void ScreenMus::OnDisplaysChanged( | 126 void ScreenMus::OnDisplaysChanged( |
| 120 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | 127 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { |
| 121 for (size_t i = 0; i < ws_displays.size(); ++i) { | 128 for (size_t i = 0; i < ws_displays.size(); ++i) { |
| 122 const bool is_primary = ws_displays[i]->is_primary; | 129 const display::Display& display = ws_displays[i]->display; |
| 123 ProcessDisplayChanged(ws_displays[i]->display, is_primary); | 130 const bool is_primary = |
| 131 display.id() == display_list()->GetPrimaryDisplayIterator()->id(); |
| 132 ProcessDisplayChanged(display, is_primary); |
| 124 if (is_primary) { | 133 if (is_primary) { |
| 125 WindowManagerFrameValues frame_values = | 134 WindowManagerFrameValues frame_values = |
| 126 ws_displays[i] | 135 ws_displays[i] |
| 127 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 136 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 128 WindowManagerFrameValues::SetInstance(frame_values); | 137 WindowManagerFrameValues::SetInstance(frame_values); |
| 129 if (delegate_) | 138 if (delegate_) |
| 130 delegate_->OnWindowManagerFrameValuesChanged(); | 139 delegate_->OnWindowManagerFrameValuesChanged(); |
| 131 } | 140 } |
| 132 } | 141 } |
| 133 } | 142 } |
| 134 | 143 |
| 135 void ScreenMus::OnDisplayRemoved(int64_t id) { | 144 void ScreenMus::OnDisplayRemoved(int64_t display_id) { |
| 136 display_list()->RemoveDisplay(id); | 145 display_list()->RemoveDisplay(display_id); |
| 146 } |
| 147 |
| 148 void ScreenMus::OnPrimaryDisplayChanged(int64_t primary_display_id) { |
| 149 // TODO(kylechar): DisplayList would need to change to handle having no |
| 150 // primary display. |
| 151 if (primary_display_id == display::Display::kInvalidDisplayID) |
| 152 return; |
| 153 |
| 154 ProcessDisplayChanged(*display_list()->FindDisplayById(primary_display_id), |
| 155 true); |
| 137 } | 156 } |
| 138 | 157 |
| 139 } // namespace views | 158 } // namespace views |
| OLD | NEW |