Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / apps / native_app_window_cocoa.h
blob9a2eaf3481797873b957f508c9deae283e19f869
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 "apps/native_app_window.h"
12 #include "apps/shell_window.h"
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/memory/scoped_ptr.h"
15 #import "chrome/browser/ui/cocoa/browser_command_executor.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "extensions/common/draggable_region.h"
18 #include "ui/gfx/rect.h"
20 class ExtensionKeybindingRegistryCocoa;
21 class Profile;
22 class NativeAppWindowCocoa;
23 @class ShellNSWindow;
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
29 <NSWindowDelegate,
30 BrowserCommandExecutor> {
31 @private
32 NativeAppWindowCocoa* appWindow_; // Weak; owns self.
35 @property(assign, nonatomic) NativeAppWindowCocoa* appWindow;
37 // Consults the Command Registry to see if this |event| needs to be handled as
38 // an extension command and returns YES if so (NO otherwise).
39 - (BOOL)handledByExtensionCommand:(NSEvent*)event;
41 @end
43 // Cocoa bridge to AppWindow.
44 class NativeAppWindowCocoa : public apps::NativeAppWindow {
45 public:
46 NativeAppWindowCocoa(apps::ShellWindow* shell_window,
47 const apps::ShellWindow::CreateParams& params);
49 // ui::BaseWindow implementation.
50 virtual bool IsActive() const OVERRIDE;
51 virtual bool IsMaximized() const OVERRIDE;
52 virtual bool IsMinimized() const OVERRIDE;
53 virtual bool IsFullscreen() const OVERRIDE;
54 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
55 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
56 virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
57 virtual gfx::Rect GetBounds() const OVERRIDE;
58 virtual void Show() OVERRIDE;
59 virtual void ShowInactive() OVERRIDE;
60 virtual void Hide() OVERRIDE;
61 virtual void Close() OVERRIDE;
62 virtual void Activate() OVERRIDE;
63 virtual void Deactivate() OVERRIDE;
64 virtual void Maximize() OVERRIDE;
65 virtual void Minimize() OVERRIDE;
66 virtual void Restore() OVERRIDE;
67 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
68 virtual void FlashFrame(bool flash) OVERRIDE;
69 virtual bool IsAlwaysOnTop() const OVERRIDE;
71 // Called when the window is about to be closed.
72 void WindowWillClose();
74 // Called when the window is focused.
75 void WindowDidBecomeKey();
77 // Called when the window is defocused.
78 void WindowDidResignKey();
80 // Called when the window is resized.
81 void WindowDidResize();
83 // Called when the window is moved.
84 void WindowDidMove();
86 // Called when the window is minimized.
87 void WindowDidMiniaturize();
89 // Called when the window is un-minimized.
90 void WindowDidDeminiaturize();
92 // Called when the window is zoomed (maximized or de-maximized).
93 void WindowWillZoom();
95 // Called to handle a key event.
96 bool HandledByExtensionCommand(NSEvent* event);
98 // Called to handle a mouse event.
99 void HandleMouseEvent(NSEvent* event);
101 // Returns true if |point| in local Cocoa coordinate system falls within
102 // the draggable region.
103 bool IsWithinDraggableRegion(NSPoint point) const;
105 NSRect restored_bounds() const { return restored_bounds_; }
106 bool use_system_drag() const { return use_system_drag_; }
108 protected:
109 // NativeAppWindow implementation.
110 virtual void SetFullscreen(bool fullscreen) OVERRIDE;
111 virtual bool IsFullscreenOrPending() const OVERRIDE;
112 virtual bool IsDetached() const OVERRIDE;
113 virtual void UpdateWindowIcon() OVERRIDE;
114 virtual void UpdateWindowTitle() OVERRIDE;
115 virtual void UpdateInputRegion(scoped_ptr<SkRegion> region) OVERRIDE;
116 virtual void UpdateDraggableRegions(
117 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
118 virtual void HandleKeyboardEvent(
119 const content::NativeWebKeyboardEvent& event) OVERRIDE;
120 virtual void RenderViewHostChanged() OVERRIDE;
121 virtual gfx::Insets GetFrameInsets() const OVERRIDE;
123 // These are used to simulate Mac-style hide/show. Since windows can be hidden
124 // and shown using the app.window API, this sets is_hidden_with_app_ to
125 // differentiate the reason a window was hidden.
126 virtual void ShowWithApp() OVERRIDE;
127 virtual void HideWithApp() OVERRIDE;
129 // WebContentsModalDialogHost implementation.
130 virtual gfx::NativeView GetHostView() const OVERRIDE;
131 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
132 virtual void AddObserver(
133 web_modal::WebContentsModalDialogHostObserver* observer) OVERRIDE;
134 virtual void RemoveObserver(
135 web_modal::WebContentsModalDialogHostObserver* observer) OVERRIDE;
137 private:
138 virtual ~NativeAppWindowCocoa();
140 ShellNSWindow* window() const;
142 content::WebContents* web_contents() const {
143 return shell_window_->web_contents();
145 const extensions::Extension* extension() const {
146 return shell_window_->extension();
149 // Returns the WindowStyleMask based on the type of window frame.
150 // Specifically, this includes NSResizableWindowMask if the window is
151 // resizable, and does not include NSTexturedBackgroundWindowMask when a
152 // native frame is used.
153 NSUInteger GetWindowStyleMask() const;
155 void InstallView();
156 void UninstallView();
157 void InstallDraggableRegionViews();
158 void UpdateDraggableRegionsForSystemDrag(
159 const std::vector<extensions::DraggableRegion>& regions,
160 const extensions::DraggableRegion* draggable_area);
161 void UpdateDraggableRegionsForCustomDrag(
162 const std::vector<extensions::DraggableRegion>& regions);
164 // Cache |restored_bounds_| only if the window is currently restored.
165 void UpdateRestoredBounds();
167 // Hides the window unconditionally. Used by Hide and HideWithApp.
168 void HideWithoutMarkingHidden();
170 apps::ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow.
172 bool has_frame_;
174 // Whether this window is hidden according to the app.window API. This is set
175 // by Hide, Show, and ShowInactive.
176 bool is_hidden_;
177 // Whether this window last became hidden due to a request to hide the entire
178 // app, e.g. via the dock menu or Cmd+H. This is set by Hide/ShowWithApp.
179 bool is_hidden_with_app_;
181 bool is_maximized_;
182 bool is_fullscreen_;
183 NSRect restored_bounds_;
185 gfx::Size min_size_;
186 gfx::Size max_size_;
187 bool resizable_;
189 base::scoped_nsobject<NativeAppWindowController> window_controller_;
190 NSInteger attention_request_id_; // identifier from requestUserAttention
192 // Indicates whether system drag or custom drag should be used, depending on
193 // the complexity of draggable regions.
194 bool use_system_drag_;
196 // For system drag, the whole window is draggable and the non-draggable areas
197 // have to been explicitly excluded.
198 std::vector<gfx::Rect> system_drag_exclude_areas_;
200 // For custom drag, the whole window is non-draggable and the draggable region
201 // has to been explicitly provided.
202 scoped_ptr<SkRegion> draggable_region_; // used in custom drag.
204 // Mouse location since the last mouse event, in screen coordinates. This is
205 // used in custom drag to compute the window movement.
206 NSPoint last_mouse_location_;
208 // The Extension Command Registry used to determine which keyboard events to
209 // handle.
210 scoped_ptr<ExtensionKeybindingRegistryCocoa> extension_keybinding_registry_;
212 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoa);
215 #endif // CHROME_BROWSER_UI_COCOA_APPS_NATIVE_APP_WINDOW_COCOA_H_