Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / apps / native_app_window_cocoa.h
blob50c6150c4cb79ae4b65fd32be1f3eb5840cb37a4
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_APPS_NATIVE_APP_WINDOW_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_APPS_NATIVE_APP_WINDOW_COCOA_H_
8 #import <Cocoa/Cocoa.h>
9 #include <vector>
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "extensions/browser/app_window/app_window.h"
15 #include "extensions/browser/app_window/native_app_window.h"
16 #include "extensions/browser/app_window/size_constraints.h"
17 #include "extensions/common/draggable_region.h"
18 #include "ui/base/accelerators/accelerator_manager.h"
19 #include "ui/gfx/geometry/rect.h"
21 @class AppNSWindow;
22 class ExtensionKeybindingRegistryCocoa;
23 class NativeAppWindowCocoa;
24 class SkRegion;
26 // A window controller for a minimal window to host a web app view. Passes
27 // Objective-C notifications to the C++ bridge.
28 @interface NativeAppWindowController : NSWindowController<NSWindowDelegate> {
29 @private
30 NativeAppWindowCocoa* appWindow_; // Weak; owns self.
31 base::scoped_nsobject<NSView> titlebar_background_view_;
34 @property(assign, nonatomic) NativeAppWindowCocoa* appWindow;
36 // NativeAppWindowController will retain this view and call
37 // -[NSView setNeedsDisplay:YES] when the window changes main status. This is
38 // necessary because it does not always happen. See http://crbug.com/508722.
39 - (void)setTitlebarBackgroundView:(NSView*)view;
41 // Consults the Command Registry to see if this |event| needs to be handled as
42 // an extension command and returns YES if so (NO otherwise).
43 // Only extensions with the given |priority| are considered.
44 - (BOOL)handledByExtensionCommand:(NSEvent*)event
45 priority:(ui::AcceleratorManager::HandlerPriority)priority;
47 @end
49 // Cocoa bridge to AppWindow.
50 class NativeAppWindowCocoa : public extensions::NativeAppWindow,
51 public content::WebContentsObserver {
52 public:
53 NativeAppWindowCocoa(extensions::AppWindow* app_window,
54 const extensions::AppWindow::CreateParams& params);
56 // ui::BaseWindow implementation.
57 bool IsActive() const override;
58 bool IsMaximized() const override;
59 bool IsMinimized() const override;
60 bool IsFullscreen() const override;
61 gfx::NativeWindow GetNativeWindow() const override;
62 gfx::Rect GetRestoredBounds() const override;
63 ui::WindowShowState GetRestoredState() const override;
64 gfx::Rect GetBounds() const override;
65 void Show() override;
66 void ShowInactive() override;
67 void Hide() override;
68 void Close() override;
69 void Activate() override;
70 void Deactivate() override;
71 void Maximize() override;
72 void Minimize() override;
73 void Restore() override;
74 void SetBounds(const gfx::Rect& bounds) override;
75 void FlashFrame(bool flash) override;
76 bool IsAlwaysOnTop() const override;
78 // Called when the window is about to be closed.
79 void WindowWillClose();
81 // Called when the window is focused.
82 void WindowDidBecomeKey();
84 // Called when the window is defocused.
85 void WindowDidResignKey();
87 // Called when the window finishes resizing, i.e. after zoom/unzoom, after
88 // entering/leaving fullscreen, and after a user is done resizing.
89 void WindowDidFinishResize();
91 // Called when the window is resized. This is called repeatedly during a
92 // zoom/unzoom, and while a user is resizing.
93 void WindowDidResize();
95 // Called when the window is moved.
96 void WindowDidMove();
98 // Called when the window is minimized.
99 void WindowDidMiniaturize();
101 // Called when the window is un-minimized.
102 void WindowDidDeminiaturize();
104 // Called when the window is zoomed (maximized or de-maximized).
105 void WindowWillZoom();
107 // Called when the window enters fullscreen.
108 void WindowDidEnterFullscreen();
110 // Called when the window exits fullscreen.
111 void WindowDidExitFullscreen();
113 // Called to handle a key event.
114 bool HandledByExtensionCommand(
115 NSEvent* event,
116 ui::AcceleratorManager::HandlerPriority priority);
118 // Returns true if |point| in local Cocoa coordinate system falls within
119 // the draggable region.
120 bool IsWithinDraggableRegion(NSPoint point) const;
122 NSRect restored_bounds() const { return restored_bounds_; }
124 protected:
125 // NativeAppWindow implementation.
126 void SetFullscreen(int fullscreen_types) override;
127 bool IsFullscreenOrPending() const override;
128 void UpdateWindowIcon() override;
129 void UpdateWindowTitle() override;
130 void UpdateShape(scoped_ptr<SkRegion> region) override;
131 void UpdateDraggableRegions(
132 const std::vector<extensions::DraggableRegion>& regions) override;
133 SkRegion* GetDraggableRegion() override;
134 void HandleKeyboardEvent(
135 const content::NativeWebKeyboardEvent& event) override;
136 bool IsFrameless() const override;
137 bool HasFrameColor() const override;
138 SkColor ActiveFrameColor() const override;
139 SkColor InactiveFrameColor() const override;
140 gfx::Insets GetFrameInsets() const override;
141 bool CanHaveAlphaEnabled() const override;
143 // These are used to simulate Mac-style hide/show. Since windows can be hidden
144 // and shown using the app.window API, this sets is_hidden_with_app_ to
145 // differentiate the reason a window was hidden.
146 void ShowWithApp() override;
147 void HideWithApp() override;
148 gfx::Size GetContentMinimumSize() const override;
149 gfx::Size GetContentMaximumSize() const override;
150 void SetContentSizeConstraints(const gfx::Size& min_size,
151 const gfx::Size& max_size) override;
152 void SetVisibleOnAllWorkspaces(bool always_visible) override;
154 // WebContentsObserver implementation.
155 void RenderViewCreated(content::RenderViewHost* rvh) override;
157 void SetAlwaysOnTop(bool always_on_top) override;
159 // WebContentsModalDialogHost implementation.
160 gfx::NativeView GetHostView() const override;
161 gfx::Point GetDialogPosition(const gfx::Size& size) override;
162 gfx::Size GetMaximumDialogSize() override;
163 void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
164 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;
166 private:
167 ~NativeAppWindowCocoa() override;
169 AppNSWindow* window() const;
170 content::WebContents* WebContents() const;
172 // Returns the WindowStyleMask based on the type of window frame.
173 // This includes NSResizableWindowMask if the window is resizable.
174 NSUInteger GetWindowStyleMask() const;
176 void InstallView();
177 void UninstallView();
178 void UpdateDraggableRegionViews();
180 // Cache |restored_bounds_| only if the window is currently restored.
181 void UpdateRestoredBounds();
183 // Hides the window unconditionally. Used by Hide and HideWithApp.
184 void HideWithoutMarkingHidden();
186 extensions::AppWindow* app_window_; // weak - AppWindow owns NativeAppWindow.
188 bool has_frame_;
190 // Whether this window last became hidden due to a request to hide the entire
191 // app, e.g. via the dock menu or Cmd+H. This is set by Hide/ShowWithApp.
192 bool is_hidden_with_app_;
194 bool is_maximized_;
195 bool is_fullscreen_;
196 NSRect restored_bounds_;
198 bool is_resizable_;
199 bool shows_resize_controls_;
200 bool shows_fullscreen_controls_;
202 extensions::SizeConstraints size_constraints_;
204 bool has_frame_color_;
205 SkColor active_frame_color_;
206 SkColor inactive_frame_color_;
208 base::scoped_nsobject<NativeAppWindowController> window_controller_;
210 // For system drag, the whole window is draggable and the non-draggable areas
211 // have to been explicitly excluded.
212 std::vector<extensions::DraggableRegion> draggable_regions_;
214 // The Extension Command Registry used to determine which keyboard events to
215 // handle.
216 scoped_ptr<ExtensionKeybindingRegistryCocoa> extension_keybinding_registry_;
218 // Tracks the last time the extension asked the window to activate.
219 base::Time last_activate_;
221 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoa);
224 #endif // CHROME_BROWSER_UI_COCOA_APPS_NATIVE_APP_WINDOW_COCOA_H_