Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / apps / native_app_window_cocoa.mm
index 2d949c0..395e1d3 100644 (file)
@@ -112,15 +112,18 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
     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;
 }
@@ -344,13 +347,6 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
   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_];
@@ -414,7 +410,7 @@ void NativeAppWindowCocoa::InstallView() {
     // prevent them from doing so in a frameless app window.
     [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO];
 
-    InstallDraggableRegionViews();
+    UpdateDraggableRegionViews();
   }
 }
 
@@ -641,13 +637,8 @@ void NativeAppWindowCocoa::UpdateDraggableRegions(
   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() {
@@ -663,13 +654,15 @@ void NativeAppWindowCocoa::HandleKeyboardEvent(
   [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.
@@ -681,11 +674,17 @@ void NativeAppWindowCocoa::InstallDraggableRegionViews() {
     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]);
@@ -693,7 +692,6 @@ void NativeAppWindowCocoa::InstallDraggableRegionViews() {
                                        webViewHeight - iter->bottom(),
                                        iter->width(),
                                        iter->height())];
-    [controlRegion setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
     [webView addSubview:controlRegion];
   }
 }
@@ -830,6 +828,7 @@ void NativeAppWindowCocoa::WindowDidFinishResize() {
 
 void NativeAppWindowCocoa::WindowDidResize() {
   app_window_->OnNativeWindowChanged();
+  UpdateDraggableRegionViews();
 }
 
 void NativeAppWindowCocoa::WindowDidMove() {
@@ -904,7 +903,7 @@ void NativeAppWindowCocoa::SetContentSizeConstraints(
   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()];