const std::vector<extensions::DraggableRegion>& regions,
int width,
int height) {
- scoped_ptr<SkRegion> draggable(
- AppWindow::RawDraggableRegionsToSkRegion(regions));
- scoped_ptr<SkRegion> non_draggable(new SkRegion);
- non_draggable->op(0, 0, width, height, SkRegion::kUnion_Op);
- non_draggable->op(*draggable, SkRegion::kDifference_Op);
-
std::vector<gfx::Rect> result;
- for (SkRegion::Iterator it(*non_draggable); !it.done(); it.next()) {
- result.push_back(gfx::SkIRectToRect(it.rect()));
+ if (regions.empty()) {
+ result.push_back(gfx::Rect(0, 0, width, height));
+ } else {
+ scoped_ptr<SkRegion> draggable(
+ AppWindow::RawDraggableRegionsToSkRegion(regions));
+ scoped_ptr<SkRegion> non_draggable(new SkRegion);
+ non_draggable->op(0, 0, width, height, SkRegion::kUnion_Op);
+ non_draggable->op(*draggable, SkRegion::kDifference_Op);
+ for (SkRegion::Iterator it(*non_draggable); !it.done(); it.next()) {
+ result.push_back(gfx::SkIRectToRect(it.rect()));
+ }
}
return result;
}
NSView* view = web_contents()->GetView()->GetNativeView();
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
- // By default, the whole frameless window is not draggable.
- if (!has_frame_) {
- gfx::Rect window_bounds(
- 0, 0, NSWidth(cocoa_bounds), NSHeight(cocoa_bounds));
- system_drag_exclude_areas_.push_back(window_bounds);
- }
-
InstallView();
[[window_controller_ window] setDelegate:window_controller_];
// prevent them from doing so in a frameless app window.
[[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO];
- InstallDraggableRegionViews();
+ UpdateDraggableRegionViews();
}
}
if (has_frame_)
return;
- // Draggable regions is implemented by having the whole web view draggable
- // (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
- NSView* web_view = web_contents()->GetView()->GetNativeView();
- system_drag_exclude_areas_ = CalculateNonDraggableRegions(
- regions, NSWidth([web_view bounds]), NSHeight([web_view bounds]));
-
- InstallDraggableRegionViews();
+ draggable_regions_ = regions;
+ UpdateDraggableRegionViews();
}
SkRegion* NativeAppWindowCocoa::GetDraggableRegion() {
[window() redispatchKeyEvent:event.os_event];
}
-void NativeAppWindowCocoa::InstallDraggableRegionViews() {
- DCHECK(!has_frame_);
+void NativeAppWindowCocoa::UpdateDraggableRegionViews() {
+ if (has_frame_)
+ return;
// 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 webViewWidth = NSWidth([webView bounds]);
NSInteger webViewHeight = NSHeight([webView bounds]);
// Remove all ControlRegionViews that are added last time.
if ([subview isKindOfClass:[ControlRegionView class]])
[subview removeFromSuperview];
- // Create and add ControlRegionView for each region that needs to be excluded
- // from the dragging.
+ // Draggable regions is implemented by having the whole web view draggable
+ // (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
+ std::vector<gfx::Rect> system_drag_exclude_areas =
+ CalculateNonDraggableRegions(
+ draggable_regions_, webViewWidth, webViewHeight);
+
+ // Create and add a ControlRegionView for each region that needs to be
+ // excluded from the dragging.
for (std::vector<gfx::Rect>::const_iterator iter =
- system_drag_exclude_areas_.begin();
- iter != system_drag_exclude_areas_.end();
+ system_drag_exclude_areas.begin();
+ iter != system_drag_exclude_areas.end();
++iter) {
base::scoped_nsobject<NSView> controlRegion(
[[ControlRegionView alloc] initWithFrame:NSZeroRect]);
webViewHeight - iter->bottom(),
iter->width(),
iter->height())];
- [controlRegion setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[webView addSubview:controlRegion];
}
}
void NativeAppWindowCocoa::WindowDidResize() {
app_window_->OnNativeWindowChanged();
+ UpdateDraggableRegionViews();
}
void NativeAppWindowCocoa::WindowDidMove() {
shows_resize_controls_ =
is_resizable_ && !size_constraints_.HasFixedSize();
shows_fullscreen_controls_ =
- is_resizable_ && !size_constraints_.HasMaximumSize();
+ is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_;
if (!is_fullscreen_) {
[window() setStyleMask:GetWindowStyleMask()];