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