Commit 50fb66aa authored by jianli@chromium.org's avatar jianli@chromium.org

Draggable region support for frameless app window on Mac.

BUG=134169
TEST=Manual test by dragging frameless window


Review URL: https://chromiumcodereview.appspot.com/10823195

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150994 0039d316-1c4b-4281-b951-d872f2087c98
parent 7f045b86
......@@ -6,9 +6,11 @@
#define CHROME_BROWSER_UI_COCOA_EXTENSIONS_SHELL_WINDOW_COCOA_H_
#import <Cocoa/Cocoa.h>
#include <vector>
#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/draggable_region.h"
#include "ui/gfx/rect.h"
class Profile;
......@@ -70,10 +72,15 @@ class ShellWindowCocoa : public ShellWindow {
private:
virtual ~ShellWindowCocoa();
// ShellWindow implementation.
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
NSWindow* window() const;
void InstallView();
void UninstallView();
void InstallDraggableRegionViews();
bool has_frame_;
......@@ -83,6 +90,8 @@ class ShellWindowCocoa : public ShellWindow {
scoped_nsobject<ShellWindowController> window_controller_;
NSInteger attention_request_id_; // identifier from requestUserAttention
std::vector<extensions::DraggableRegion> draggable_regions_;
DISALLOW_COPY_AND_ASSIGN(ShellWindowCocoa);
};
......
......@@ -139,18 +139,6 @@ ShellWindowCocoa::ShellWindowCocoa(Profile* profile,
NSView* view = web_contents()->GetView()->GetNativeView();
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
if (!has_frame_) {
// TODO(jeremya): this is a temporary hack to allow moving the window while
// we still don't have proper draggable region support.
NSView* controlRegion = [[ControlRegionView alloc] init];
[controlRegion setFrame:NSMakeRect(0, 0, NSWidth([view bounds]),
NSHeight([view bounds]) - 20)];
[controlRegion setAutoresizingMask:
NSViewWidthSizable | NSViewHeightSizable];
[view addSubview:controlRegion];
[controlRegion release];
}
InstallView();
[[window_controller_ window] setDelegate:window_controller_];
......@@ -176,6 +164,8 @@ void ShellWindowCocoa::InstallView() {
[[window() standardWindowButton:NSWindowZoomButton] setHidden:YES];
[[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window() standardWindowButton:NSWindowCloseButton] setHidden:YES];
InstallDraggableRegionViews();
}
}
......@@ -339,6 +329,50 @@ void ShellWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[window() setFrame:cocoa_bounds display:YES];
}
void ShellWindowCocoa::UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) {
// Draggable region is not supported for non-frameless window.
if (has_frame_)
return;
draggable_regions_ = regions;
InstallDraggableRegionViews();
}
void ShellWindowCocoa::InstallDraggableRegionViews() {
DCHECK(!has_frame_);
// All ControlRegionViews should be added as children of the WebContentsView,
// because WebContentsView will be removed and re-added when entering and
// leaving fullscreen mode.
NSView* webView = web_contents()->GetView()->GetNativeView();
NSInteger webViewHeight = NSHeight([webView bounds]);
// Remove all ControlRegionViews that are added last time.
// Note that [webView subviews] returns the view's mutable internal array and
// it should be copied to avoid mutating the original array while enumerating
// it.
scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
for (NSView* subview in subviews.get())
if ([subview isKindOfClass:[ControlRegionView class]])
[subview removeFromSuperview];
// Create and add ControlRegionView for each region that needs to be excluded
// from the dragging.
for (std::vector<extensions::DraggableRegion>::const_iterator iter =
draggable_regions_.begin();
iter != draggable_regions_.end();
++iter) {
const extensions::DraggableRegion& region = *iter;
scoped_nsobject<NSView> controlRegion([[ControlRegionView alloc] init]);
[controlRegion setFrame:NSMakeRect(region.bounds.x(),
webViewHeight - region.bounds.bottom(),
region.bounds.width(),
region.bounds.height())];
[webView addSubview:controlRegion];
}
}
void ShellWindowCocoa::FlashFrame(bool flash) {
if (flash) {
attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment