Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Unified Diff: ui/aura/mus/window_tree_client.h

Issue 2445163002: Make aura work with mus (Closed)
Patch Set: NON_EXPORTED_BASE_CLASS Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/mus/window_port_mus.cc ('k') | ui/aura/mus/window_tree_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/window_tree_client.h
diff --git a/services/ui/public/cpp/window_tree_client.h b/ui/aura/mus/window_tree_client.h
similarity index 65%
copy from services/ui/public/cpp/window_tree_client.h
copy to ui/aura/mus/window_tree_client.h
index 9d993fad78395de4d2b54eadc9111f4869049513..9af2e58fd1d6103a213acf093ac55e8ddfb2fe6c 100644
--- a/services/ui/public/cpp/window_tree_client.h
+++ b/ui/aura/mus/window_tree_client.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SERVICES_UI_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_
-#define SERVICES_UI_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_
+#ifndef UI_AURA_MUS_WINDOW_TREE_CLIENT_H_
+#define UI_AURA_MUS_WINDOW_TREE_CLIENT_H_
#include <stdint.h>
@@ -14,15 +14,18 @@
#include <vector>
#include "base/atomicops.h"
+#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "services/ui/common/types.h"
-#include "services/ui/public/cpp/window.h"
-#include "services/ui/public/cpp/window_manager_delegate.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
+#include "ui/aura/aura_export.h"
+#include "ui/aura/client/capture_client_observer.h"
+#include "ui/aura/client/focus_change_observer.h"
+#include "ui/aura/mus/mus_types.h"
+#include "ui/aura/mus/window_manager_delegate.h"
namespace display {
class Display;
@@ -30,19 +33,31 @@ class Display;
namespace gfx {
class Insets;
-class Size;
}
namespace service_manager {
class Connector;
}
-namespace ui {
+namespace aura {
+class InFlightCaptureChange;
class InFlightChange;
+class InFlightFocusChange;
+class InFlightPropertyChange;
+class WindowMus;
+class WindowPortMus;
+struct WindowPortInitData;
+struct WindowPortPropertyData;
class WindowTreeClientDelegate;
class WindowTreeClientPrivate;
class WindowTreeClientObserver;
-enum class ChangeType;
+class WindowTreeHost;
+
+namespace client {
+class FocusClient;
+}
+
+using EventResultCallback = base::Callback<void(ui::mojom::EventResult)>;
// Manages the connection with mus.
//
@@ -52,14 +67,17 @@ enum class ChangeType;
//
// When WindowTreeClient is deleted all windows are deleted (and observers
// notified).
-class WindowTreeClient : public mojom::WindowTreeClient,
- public mojom::WindowManager,
- public WindowManagerClient {
+class AURA_EXPORT WindowTreeClient
+ : NON_EXPORTED_BASE(public ui::mojom::WindowTreeClient),
+ NON_EXPORTED_BASE(public ui::mojom::WindowManager),
+ public WindowManagerClient,
+ public client::CaptureClientObserver,
+ public client::FocusChangeObserver {
public:
explicit WindowTreeClient(
WindowTreeClientDelegate* delegate,
WindowManagerDelegate* window_manager_delegate = nullptr,
- mojom::WindowTreeClientRequest request = nullptr);
+ ui::mojom::WindowTreeClientRequest request = nullptr);
~WindowTreeClient() override;
// Establishes the connection by way of the WindowTreeFactory.
@@ -74,90 +92,42 @@ class WindowTreeClient : public mojom::WindowTreeClient,
bool connected() const { return tree_ != nullptr; }
ClientSpecificId client_id() const { return client_id_; }
- // API exposed to the window implementations that pushes local changes to the
- // service.
- void DestroyWindow(Window* window);
-
- // These methods take TransportIds. For windows owned by the current client,
- // the client id high word can be zero. In all cases, the TransportId 0x1
- // refers to the root window.
- void AddChild(Window* parent, Id child_id);
- void RemoveChild(Window* parent, Id child_id);
-
- void AddTransientWindow(Window* window, Id transient_window_id);
- void RemoveTransientWindowFromParent(Window* window);
-
- void SetModal(Window* window);
-
- void Reorder(Window* window,
- Id relative_window_id,
- mojom::OrderDirection direction);
-
- // Returns true if the specified window was created by this client.
- bool WasCreatedByThisClient(const Window* window) const;
-
- void SetBounds(Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& bounds);
- void SetCapture(Window* window);
- void ReleaseCapture(Window* window);
- void SetClientArea(Id window_id,
+ void SetClientArea(Window* window,
const gfx::Insets& client_area,
const std::vector<gfx::Rect>& additional_client_areas);
- void SetHitTestMask(Id window_id, const gfx::Rect& mask);
- void ClearHitTestMask(Id window_id);
- void SetFocus(Window* window);
- void SetCanFocus(Id window_id, bool can_focus);
+ void SetHitTestMask(Window* window, const gfx::Rect& mask);
+ void ClearHitTestMask(Window* window);
+ void SetCanFocus(Window* window, bool can_focus);
void SetCanAcceptDrops(Id window_id, bool can_accept_drops);
void SetCanAcceptEvents(Id window_id, bool can_accept_events);
- void SetPredefinedCursor(Id window_id, ui::mojom::Cursor cursor_id);
- void SetVisible(Window* window, bool visible);
- void SetOpacity(Window* window, float opacity);
- void SetProperty(Window* window,
- const std::string& name,
- mojo::Array<uint8_t> data);
- void SetWindowTextInputState(Id window_id, mojo::TextInputStatePtr state);
- void SetImeVisibility(Id window_id,
+ void SetPredefinedCursor(WindowMus* window,
+ ui::mojom::Cursor old_cursor,
+ ui::mojom::Cursor new_cursor);
+ void SetWindowTextInputState(WindowMus* window,
+ mojo::TextInputStatePtr state);
+ void SetImeVisibility(WindowMus* window,
bool visible,
mojo::TextInputStatePtr state);
+ // TODO: this should take a window, not an id.
void Embed(Id window_id,
- mojom::WindowTreeClientPtr client,
+ ui::mojom::WindowTreeClientPtr client,
uint32_t flags,
- const mojom::WindowTree::EmbedCallback& callback);
+ const ui::mojom::WindowTree::EmbedCallback& callback);
+ // TODO: this should move to WindowManager.
void RequestClose(Window* window);
void AttachCompositorFrameSink(
Id window_id,
- mojom::CompositorFrameSinkType type,
+ ui::mojom::CompositorFrameSinkType type,
cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink,
cc::mojom::MojoCompositorFrameSinkClientPtr client);
- void OnWindowSurfaceDetached(Id window_id,
- const cc::SurfaceSequence& sequence);
-
- // Sets the input capture to |window| without notifying the server.
- void LocalSetCapture(Window* window);
- // Sets focus to |window| without notifying the server.
- void LocalSetFocus(Window* window);
-
- // Start/stop tracking windows. While tracked, they can be retrieved via
- // WindowTreeClient::GetWindowById.
- void AddWindow(Window* window);
-
- bool IsRoot(Window* window) const { return roots_.count(window) > 0; }
-
- void OnWindowDestroying(Window* window);
-
- // Called after the window's observers have been notified of destruction (as
- // the last step of ~Window).
- void OnWindowDestroyed(Window* window);
-
- Window* GetWindowByServerId(Id id);
+ bool IsRoot(WindowMus* window) const { return roots_.count(window) > 0; }
// Returns the root of this connection.
- const std::set<Window*>& GetRoots();
+ std::set<Window*> GetRoots();
// Returns the Window with input capture; null if no window has requested
// input capture, or if another app has capture.
@@ -167,9 +137,6 @@ class WindowTreeClient : public mojom::WindowTreeClient,
// is focused.
Window* GetFocusedWindow();
- // Sets focus to null. This does nothing if focus is currently null.
- void ClearFocus();
-
// Returns the current location of the mouse on screen. Note: this method may
// race the asynchronous initialization; but in that case we return (0, 0).
gfx::Point GetCursorScreenPoint();
@@ -203,39 +170,38 @@ class WindowTreeClient : public mojom::WindowTreeClient,
// does nothing.)
void CancelWindowMove(Window* window);
- // Creates and returns a new Window (which is owned by the window server).
- // Windows are initially hidden, use SetVisible(true) to show.
- Window* NewWindow() { return NewWindow(nullptr); }
- Window* NewWindow(
- const std::map<std::string, std::vector<uint8_t>>* properties);
- Window* NewTopLevelWindow(
- const std::map<std::string, std::vector<uint8_t>>* properties);
-
void AddObserver(WindowTreeClientObserver* observer);
void RemoveObserver(WindowTreeClientObserver* observer);
-#if !defined(NDEBUG)
- std::string GetDebugWindowHierarchy() const;
- void BuildDebugInfo(const std::string& depth,
- Window* window,
- std::string* result) const;
-#endif
-
private:
+ friend class InFlightCaptureChange;
+ friend class InFlightFocusChange;
+ friend class InFlightPropertyChange;
+ friend class WindowPortMus;
friend class WindowTreeClientPrivate;
- struct CurrentDragState;
+ enum class WindowTreeHostType { EMBED, TOP_LEVEL, DISPLAY };
- enum class NewWindowType {
- CHILD,
- TOP_LEVEL,
- };
+ struct CurrentDragState;
- using IdToWindowMap = std::map<Id, Window*>;
+ using IdToWindowMap = std::map<Id, WindowMus*>;
// TODO(sky): this assumes change_ids never wrap, which is a bad assumption.
using InFlightMap = std::map<uint32_t, std::unique_ptr<InFlightChange>>;
+ void RegisterWindowMus(WindowMus* window);
+
+ WindowMus* GetWindowByServerId(Id id);
+
+ // Returns true if the specified window was created by this client.
+ bool WasCreatedByThisClient(const WindowMus* window) const;
+
+ void SetFocusFromServer(WindowMus* window);
+ void SetFocusFromServerImpl(client::FocusClient* focus_client,
+ WindowMus* window);
+
+ void SetCaptureFromServer(WindowMus* window);
+
// Returns the oldest InFlightChange that matches |change|.
InFlightChange* GetOldestInFlightChangeMatching(const InFlightChange& change);
@@ -248,42 +214,87 @@ class WindowTreeClient : public mojom::WindowTreeClient,
// See InFlightChange for details on how InFlightChanges are used.
bool ApplyServerChangeToExistingInFlightChange(const InFlightChange& change);
- static Id server_id(const Window* window) { return window->server_id(); }
-
- Window* BuildWindowTree(const mojo::Array<mojom::WindowDataPtr>& windows,
- Window* initial_parent);
-
- Window* NewWindowImpl(NewWindowType type,
- const Window::SharedProperties* properties);
-
- // Sets the mojom::WindowTree implementation.
- void SetWindowTree(mojom::WindowTreePtr window_tree_ptr);
-
- // Called when the mojom::WindowTree connection is lost, deletes this.
+ void BuildWindowTree(const mojo::Array<ui::mojom::WindowDataPtr>& windows,
+ WindowMus* initial_parent);
+
+ // Creates a WindowPortMus from the server side data.
+ // NOTE: this *must* be followed by SetLocalPropertiesFromServerProperties()
+ std::unique_ptr<WindowPortMus> CreateWindowPortMus(
+ const ui::mojom::WindowDataPtr& window_data);
+
+ // Sets local properties on the associated Window from the server properties.
+ void SetLocalPropertiesFromServerProperties(
+ WindowMus* window,
+ const ui::mojom::WindowDataPtr& window_data);
+
+ // Creates a WindowTreeHostMus and returns the window associated with it.
+ // The returned window is either the content window of the WindowTreeHostMus
+ // or the window created by WindowTreeHost. See WindowTreeHostMus for
+ // details.
+ // TODO(sky): it would be nice to always have a single window and not the
+ // two different. That requires ownership changes to WindowTreeHost though.
+ Window* CreateWindowTreeHost(WindowTreeHostType type,
+ const ui::mojom::WindowDataPtr& window_data,
+ Window* content_window);
+
+ WindowMus* NewWindowFromWindowData(
+ WindowMus* parent,
+ const ui::mojom::WindowDataPtr& window_data);
+
+ // Sets the ui::mojom::WindowTree implementation.
+ void SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr);
+
+ // Called when the ui::mojom::WindowTree connection is lost, deletes this.
void OnConnectionLost();
// OnEmbed() calls into this. Exposed as a separate function for testing.
- void OnEmbedImpl(mojom::WindowTree* window_tree,
+ void OnEmbedImpl(ui::mojom::WindowTree* window_tree,
ClientSpecificId client_id,
- mojom::WindowDataPtr root_data,
+ ui::mojom::WindowDataPtr root_data,
int64_t display_id,
Id focused_window_id,
bool drawn);
// Called by WmNewDisplayAdded().
- void WmNewDisplayAddedImpl(const display::Display& display,
- mojom::WindowDataPtr root_data,
- bool parent_drawn);
+ WindowTreeHost* WmNewDisplayAddedImpl(const display::Display& display,
+ ui::mojom::WindowDataPtr root_data,
+ bool parent_drawn);
+
+ std::unique_ptr<EventResultCallback> CreateEventResultCallback(
+ int32_t event_id);
void OnReceivedCursorLocationMemory(mojo::ScopedSharedBufferHandle handle);
+ // Following are called from WindowMus.
+ std::unique_ptr<WindowPortInitData> OnWindowMusCreated(WindowMus* window);
+ void OnWindowMusInitDone(WindowMus* window,
+ std::unique_ptr<WindowPortInitData> init_data);
+ void OnWindowMusDestroyed(WindowMus* window);
+ void OnWindowMusBoundsChanged(WindowMus* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds);
+ void OnWindowMusAddChild(WindowMus* parent, WindowMus* child);
+ void OnWindowMusRemoveChild(WindowMus* parent, WindowMus* child);
+ void OnWindowMusMoveChild(WindowMus* parent,
+ size_t current_index,
+ size_t dest_index);
+ void OnWindowMusSetVisible(WindowMus* window, bool visible);
+ std::unique_ptr<WindowPortPropertyData> OnWindowMusWillChangeProperty(
+ WindowMus* window,
+ const void* key);
+ void OnWindowMusPropertyChanged(WindowMus* window,
+ const void* key,
+ std::unique_ptr<WindowPortPropertyData> data);
+ void OnWindowMusSurfaceDetached(WindowMus* window,
+ const cc::SurfaceSequence& sequence);
+
// Callback passed from WmPerformMoveLoop().
void OnWmMoveLoopCompleted(uint32_t change_id, bool completed);
// Overridden from WindowTreeClient:
void OnEmbed(ClientSpecificId client_id,
- mojom::WindowDataPtr root,
- mojom::WindowTreePtr tree,
+ ui::mojom::WindowDataPtr root,
+ ui::mojom::WindowTreePtr tree,
int64_t display_id,
Id focused_window_id,
bool drawn) override;
@@ -292,7 +303,7 @@ class WindowTreeClient : public mojom::WindowTreeClient,
void OnCaptureChanged(Id new_capture_window_id,
Id old_capture_window_id) override;
void OnTopLevelCreated(uint32_t change_id,
- mojom::WindowDataPtr data,
+ ui::mojom::WindowDataPtr data,
int64_t display_id,
bool drawn) override;
void OnWindowBoundsChanged(Id window_id,
@@ -310,19 +321,20 @@ class WindowTreeClient : public mojom::WindowTreeClient,
Id window_id,
Id old_parent_id,
Id new_parent_id,
- mojo::Array<mojom::WindowDataPtr> windows) override;
+ mojo::Array<ui::mojom::WindowDataPtr> windows) override;
void OnWindowReordered(Id window_id,
Id relative_window_id,
- mojom::OrderDirection direction) override;
+ ui::mojom::OrderDirection direction) override;
void OnWindowDeleted(Id window_id) override;
void OnWindowVisibilityChanged(Id window_id, bool visible) override;
void OnWindowOpacityChanged(Id window_id,
float old_opacity,
float new_opacity) override;
void OnWindowParentDrawnStateChanged(Id window_id, bool drawn) override;
- void OnWindowSharedPropertyChanged(Id window_id,
- const mojo::String& name,
- mojo::Array<uint8_t> new_data) override;
+ void OnWindowSharedPropertyChanged(
+ Id window_id,
+ const mojo::String& name,
+ mojo::Array<uint8_t> transport_data) override;
void OnWindowInputEvent(uint32_t event_id,
Id window_id,
std::unique_ptr<ui::Event> event,
@@ -331,7 +343,7 @@ class WindowTreeClient : public mojom::WindowTreeClient,
uint32_t window_id) override;
void OnWindowFocused(Id focused_window_id) override;
void OnWindowPredefinedCursorChanged(Id window_id,
- mojom::Cursor cursor) override;
+ ui::mojom::Cursor cursor) override;
void OnWindowSurfaceChanged(Id window_id,
const cc::SurfaceId& surface_id,
const cc::SurfaceSequence& surface_sequence,
@@ -367,7 +379,7 @@ class WindowTreeClient : public mojom::WindowTreeClient,
// Overridden from WindowManager:
void OnConnect(ClientSpecificId client_id) override;
void WmNewDisplayAdded(const display::Display& display,
- mojom::WindowDataPtr root_data,
+ ui::mojom::WindowDataPtr root_data,
bool parent_drawn) override;
void WmDisplayRemoved(int64_t display_id) override;
void WmDisplayModified(const display::Display& display) override;
@@ -386,7 +398,7 @@ class WindowTreeClient : public mojom::WindowTreeClient,
bool janky) override;
void WmPerformMoveLoop(uint32_t change_id,
Id window_id,
- mojom::MoveLoopSource source,
+ ui::mojom::MoveLoopSource source,
const gfx::Point& cursor_location) override;
void WmCancelMoveLoop(uint32_t window_id) override;
void OnAccelerator(uint32_t ack_id,
@@ -395,10 +407,10 @@ class WindowTreeClient : public mojom::WindowTreeClient,
// Overridden from WindowManagerClient:
void SetFrameDecorationValues(
- mojom::FrameDecorationValuesPtr values) override;
+ ui::mojom::FrameDecorationValuesPtr values) override;
void SetNonClientCursor(Window* window, ui::mojom::Cursor cursor_id) override;
void AddAccelerator(uint32_t id,
- mojom::EventMatcherPtr event_matcher,
+ ui::mojom::EventMatcherPtr event_matcher,
const base::Callback<void(bool)>& callback) override;
void RemoveAccelerator(uint32_t id) override;
void AddActivationParent(Window* window) override;
@@ -409,6 +421,12 @@ class WindowTreeClient : public mojom::WindowTreeClient,
const gfx::Vector2d& offset,
const gfx::Insets& hit_area) override;
+ // Overriden from client::FocusChangeObserver:
+ void OnWindowFocused(Window* gained_focus, Window* lost_focus) override;
+
+ // Overriden from client::CaptureClientObserver:
+ void OnCaptureChanged(Window* lost_capture, Window* gained_capture) override;
+
// The one int in |cursor_location_mapping_|. When we read from this
// location, we must always read from it atomically.
base::subtle::Atomic32* cursor_location_memory() {
@@ -431,20 +449,24 @@ class WindowTreeClient : public mojom::WindowTreeClient,
WindowManagerDelegate* window_manager_delegate_;
- std::set<Window*> roots_;
+ std::set<WindowMus*> roots_;
IdToWindowMap windows_;
std::map<ClientSpecificId, std::set<Window*>> embedded_windows_;
- Window* capture_window_;
+ bool setting_capture_ = false;
+ WindowMus* window_setting_capture_to_ = nullptr;
+ WindowMus* capture_window_ = nullptr;
- Window* focused_window_;
+ bool setting_focus_ = false;
+ WindowMus* window_setting_focus_to_ = nullptr;
+ WindowMus* focused_window_ = nullptr;
- mojo::Binding<mojom::WindowTreeClient> binding_;
- mojom::WindowTreePtr tree_ptr_;
+ mojo::Binding<ui::mojom::WindowTreeClient> binding_;
+ ui::mojom::WindowTreePtr tree_ptr_;
// Typically this is the value contained in |tree_ptr_|, but tests may
// directly set this.
- mojom::WindowTree* tree_;
+ ui::mojom::WindowTree* tree_;
// Set to true if OnEmbed() was received.
bool is_from_embed_ = false;
@@ -457,9 +479,9 @@ class WindowTreeClient : public mojom::WindowTreeClient,
base::ObserverList<WindowTreeClientObserver> observers_;
- std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>>
+ std::unique_ptr<mojo::AssociatedBinding<ui::mojom::WindowManager>>
window_manager_internal_;
- mojom::WindowManagerClientAssociatedPtr window_manager_internal_client_;
+ ui::mojom::WindowManagerClientAssociatedPtr window_manager_internal_client_;
bool has_pointer_watcher_ = false;
@@ -492,6 +514,6 @@ class WindowTreeClient : public mojom::WindowTreeClient,
DISALLOW_COPY_AND_ASSIGN(WindowTreeClient);
};
-} // namespace ui
+} // namespace aura
-#endif // SERVICES_UI_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_
+#endif // UI_AURA_MUS_WINDOW_TREE_CLIENT_H_
« no previous file with comments | « ui/aura/mus/window_port_mus.cc ('k') | ui/aura/mus/window_tree_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698