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

Side by Side Diff: ui/views/cocoa/bridged_native_widget.h

Issue 659233002: STASH: Epic Experimental patch for toolkit-views App List on Mac Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Fix a few things. Works@master Created 6 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 unified diff | Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ 5 #ifndef UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
6 #define UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ 6 #define UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "ui/compositor/layer_owner.h"
12 #import "ui/views/focus/focus_manager.h" 13 #import "ui/views/focus/focus_manager.h"
13 #include "ui/views/ime/input_method_delegate.h" 14 #include "ui/views/ime/input_method_delegate.h"
14 #include "ui/views/views_export.h" 15 #include "ui/views/views_export.h"
15 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
16 17
18 #import "content/browser/compositor/browser_compositor_view_mac.h"
19
17 @class BridgedContentView; 20 @class BridgedContentView;
18 @class ViewsNSWindowDelegate; 21 @class ViewsNSWindowDelegate;
19 22
20 namespace ui { 23 namespace ui {
21 class InputMethod; 24 class InputMethod;
22 } 25 }
23 26
24 namespace views { 27 namespace views {
25 28
26 class InputMethod; 29 class InputMethod;
27 class NativeWidgetMac; 30 class NativeWidgetMac;
28 class View; 31 class View;
29 32
30 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or 33 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or
31 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the 34 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the
32 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. 35 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window.
33 class VIEWS_EXPORT BridgedNativeWidget : public internal::InputMethodDelegate, 36 class VIEWS_EXPORT BridgedNativeWidget
34 public FocusChangeListener { 37 : public ui::LayerDelegate,
38 public ui::LayerOwner,
39 public internal::InputMethodDelegate,
40 public FocusChangeListener,
41 public content::BrowserCompositorViewMacClient {
35 public: 42 public:
36 // Creates one side of the bridge. |parent| must not be NULL. 43 // Creates one side of the bridge. |parent| must not be NULL.
37 explicit BridgedNativeWidget(NativeWidgetMac* parent); 44 explicit BridgedNativeWidget(NativeWidgetMac* parent);
38 virtual ~BridgedNativeWidget(); 45 virtual ~BridgedNativeWidget();
39 46
40 // Initialize the bridge, "retains" ownership of |window|. 47 // Initialize the bridge, "retains" ownership of |window|.
41 void Init(base::scoped_nsobject<NSWindow> window, 48 void Init(base::scoped_nsobject<NSWindow> window,
42 const Widget::InitParams& params); 49 const Widget::InitParams& params);
43 50
44 // Sets or clears the focus manager to use for tracking focused views. 51 // Sets or clears the focus manager to use for tracking focused views.
45 // This does NOT take ownership of |focus_manager|. 52 // This does NOT take ownership of |focus_manager|.
46 void SetFocusManager(FocusManager* focus_manager); 53 void SetFocusManager(FocusManager* focus_manager);
47 54
55 // Changes the bounds of the window and the hosted layer if present.
56 void SetBounds(const gfx::Rect& new_bounds);
57
48 // Set or clears the views::View bridged by the content view. This does NOT 58 // Set or clears the views::View bridged by the content view. This does NOT
49 // take ownership of |view|. 59 // take ownership of |view|.
50 void SetRootView(views::View* view); 60 void SetRootView(views::View* view);
51 61
52 // Called internally by the NSWindowDelegate when the window is closing. 62 // Called internally by the NSWindowDelegate when the window is closing.
53 void OnWindowWillClose(); 63 void OnWindowWillClose();
54 64
55 // Called by the NSWindowDelegate when a fullscreen operation begins. If 65 // Called by the NSWindowDelegate when a fullscreen operation begins. If
56 // |target_fullscreen_state| is true, the target state is fullscreen. 66 // |target_fullscreen_state| is true, the target state is fullscreen.
57 // Otherwise, a transition has begun to come out of fullscreen. 67 // Otherwise, a transition has begun to come out of fullscreen.
58 void OnFullscreenTransitionStart(bool target_fullscreen_state); 68 void OnFullscreenTransitionStart(bool target_fullscreen_state);
59 69
60 // Called when a fullscreen transition completes. If target_fullscreen_state() 70 // Called when a fullscreen transition completes. If target_fullscreen_state()
61 // does not match |actual_fullscreen_state|, a new transition will begin. 71 // does not match |actual_fullscreen_state|, a new transition will begin.
62 void OnFullscreenTransitionComplete(bool actual_fullscreen_state); 72 void OnFullscreenTransitionComplete(bool actual_fullscreen_state);
63 73
64 // Transition the window into or out of fullscreen. This will immediately 74 // Transition the window into or out of fullscreen. This will immediately
65 // invert the value of target_fullscreen_state(). 75 // invert the value of target_fullscreen_state().
66 void ToggleDesiredFullscreenState(); 76 void ToggleDesiredFullscreenState();
67 77
78 // Called by the NSWindowDelegate when the size of the window changes.
79 void OnSizeChanged();
80
81 // Called by the NSWindowDelegate when the visibility of the window may have
82 // changed. For example, due to a (de)miniaturize operation, or the window
83 // being reordered in (or out of) the screen list.
84 void OnVisibilityChanged();
85
86 // Called by the NSWindowDelegate when the window moves to a new display or
87 // when the display properties (backing store scale factor or colorspace
88 // changes.
89 void OnDisplayChanged();
90
68 // See widget.h for documentation. 91 // See widget.h for documentation.
69 InputMethod* CreateInputMethod(); 92 InputMethod* CreateInputMethod();
70 ui::InputMethod* GetHostInputMethod(); 93 ui::InputMethod* GetHostInputMethod();
71 94
72 // The restored bounds will be derived from the current NSWindow frame unless 95 // The restored bounds will be derived from the current NSWindow frame unless
73 // fullscreen or transitioning between fullscreen states. 96 // fullscreen or transitioning between fullscreen states.
74 gfx::Rect GetRestoredBounds() const; 97 gfx::Rect GetRestoredBounds() const;
75 98
99 ui::Layer* GetOrCreateLayer();
100
76 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } 101 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; }
77 BridgedContentView* ns_view() { return bridged_view_; } 102 BridgedContentView* ns_view() { return bridged_view_; }
78 NSWindow* ns_window() { return window_; } 103 NSWindow* ns_window() { return window_; }
79 104
80 bool target_fullscreen_state() const { return target_fullscreen_state_; } 105 bool target_fullscreen_state() const { return target_fullscreen_state_; }
81 106
82 // Overridden from internal::InputMethodDelegate: 107 // Overridden from internal::InputMethodDelegate:
83 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) override; 108 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
84 109
110 // Overridden from content::BrowserCompositorViewMacClient:
111 virtual bool BrowserCompositorViewShouldAckImmediately() const OVERRIDE;
112 virtual void BrowserCompositorViewFrameSwapped(
113 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
114 virtual NSView* BrowserCompositorSuperview() OVERRIDE;
115 virtual ui::Layer* BrowserCompositorRootLayer() OVERRIDE;
116
85 private: 117 private:
86 // Closes all child windows. BridgedNativeWidget children will be destroyed. 118 // Closes all child windows. BridgedNativeWidget children will be destroyed.
87 void RemoveOrDestroyChildren(); 119 void RemoveOrDestroyChildren();
88 120
121 // Size the layer, taking into account display scale factor.
122 void SetLayerSize(const gfx::Size& size_in_dip);
123
124 void OnWindowBoundsChanged();
125
126 // Overridden from ui::LayerDelegate:
127 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
128 virtual void OnDelegatedFrameDamage(
129 const gfx::Rect& damage_rect_in_dip) OVERRIDE;
130 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
131 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE;
132
89 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. 133 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this.
90 base::scoped_nsobject<NSWindow> window_; 134 base::scoped_nsobject<NSWindow> window_;
91 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; 135 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_;
92 base::scoped_nsobject<BridgedContentView> bridged_view_; 136 base::scoped_nsobject<BridgedContentView> bridged_view_;
93 scoped_ptr<ui::InputMethod> input_method_; 137 scoped_ptr<ui::InputMethod> input_method_;
94 FocusManager* focus_manager_; // Weak. Owned by our Widget. 138 FocusManager* focus_manager_; // Weak. Owned by our Widget.
95 139
140 base::scoped_nsobject<NSView> compositor_superview_;
141 scoped_ptr<content::BrowserCompositorViewMac> compositor_view_;
142 content::BrowserCompositorViewPlaceholderMac recycling_keepalive_;
143
96 // Tracks the bounds when the window last started entering fullscreen. Used to 144 // Tracks the bounds when the window last started entering fullscreen. Used to
97 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it 145 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it
98 // has its own copy, but doesn't provide access to it). 146 // has its own copy, but doesn't provide access to it).
99 gfx::Rect bounds_before_fullscreen_; 147 gfx::Rect bounds_before_fullscreen_;
100 148
101 // Whether this window wants to be fullscreen. If a fullscreen animation is in 149 // Whether this window wants to be fullscreen. If a fullscreen animation is in
102 // progress then it might not be actually fullscreen. 150 // progress then it might not be actually fullscreen.
103 bool target_fullscreen_state_; 151 bool target_fullscreen_state_;
104 152
105 // Whether this window is in a fullscreen transition, and the fullscreen state 153 // Whether this window is in a fullscreen transition, and the fullscreen state
106 // can not currently be changed. 154 // can not currently be changed.
107 bool in_fullscreen_transition_; 155 bool in_fullscreen_transition_;
108 156
157 // Stores the value last read from -[NSWindow isVisible], to detect visibility
158 // changes.
159 bool window_visible_;
160
109 // Overridden from FocusChangeListener: 161 // Overridden from FocusChangeListener:
110 virtual void OnWillChangeFocus(View* focused_before, 162 virtual void OnWillChangeFocus(View* focused_before,
111 View* focused_now) override; 163 View* focused_now) override;
112 virtual void OnDidChangeFocus(View* focused_before, 164 virtual void OnDidChangeFocus(View* focused_before,
113 View* focused_now) override; 165 View* focused_now) override;
114 166
115 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); 167 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget);
116 }; 168 };
117 169
118 } // namespace views 170 } // namespace views
119 171
120 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ 172 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698