Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / views / widget / widget.cc
index 6de5217..73c468e 100644 (file)
@@ -171,7 +171,7 @@ Widget::Widget()
       native_widget_initialized_(false),
       native_widget_destroyed_(false),
       is_mouse_button_pressed_(false),
-      is_touch_down_(false),
+      ignore_capture_loss_(false),
       last_mouse_event_was_move_(false),
       auto_release_capture_(true),
       root_layers_dirty_(false),
@@ -227,13 +227,13 @@ Widget* Widget::CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
 
 // static
 Widget* Widget::CreateWindowWithContext(WidgetDelegate* delegate,
-                                        gfx::NativeView context) {
+                                        gfx::NativeWindow context) {
   return CreateWindowWithContextAndBounds(delegate, context, gfx::Rect());
 }
 
 // static
 Widget* Widget::CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
-                                                 gfx::NativeView context,
+                                                 gfx::NativeWindow context,
                                                  const gfx::Rect& bounds) {
   Widget* widget = new Widget;
   Widget::InitParams params;
@@ -789,6 +789,7 @@ void Widget::RunShellDrag(View* view,
                           int operation,
                           ui::DragDropTypes::DragEventSource source) {
   dragged_view_ = view;
+  OnDragWillStart();
   native_widget_->RunShellDrag(view, data, location, operation, source);
   // If the view is removed during the drag operation, dragged_view_ is set to
   // NULL.
@@ -796,6 +797,7 @@ void Widget::RunShellDrag(View* view,
     dragged_view_ = NULL;
     view->OnDragDone();
   }
+  OnDragComplete();
 }
 
 void Widget::SchedulePaintInRect(const gfx::Rect& rect) {
@@ -940,13 +942,17 @@ NativeWidget* Widget::native_widget() {
 }
 
 void Widget::SetCapture(View* view) {
+  if (!native_widget_->HasCapture()) {
+    native_widget_->SetCapture();
+
+    // Early return if setting capture was unsuccessful.
+    if (!native_widget_->HasCapture())
+      return;
+  }
+
   if (internal::NativeWidgetPrivate::IsMouseButtonDown())
     is_mouse_button_pressed_ = true;
-  if (internal::NativeWidgetPrivate::IsTouchDown())
-    is_touch_down_ = true;
   root_view_->SetMouseHandler(view);
-  if (!native_widget_->HasCapture())
-    native_widget_->SetCapture();
 }
 
 void Widget::ReleaseCapture() {
@@ -1123,17 +1129,17 @@ void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
         focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
     }
   }
-  // Size changed notifications can fire prior to full initialization
-  // i.e. during session restore.  Avoid saving session state during these
-  // startup procedures.
-  if (native_widget_initialized_)
-    SaveWindowPlacement();
+  SaveWindowPlacementIfInitialized();
 
   FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
     this,
     GetWindowBoundsInScreen()));
 }
 
+void Widget::OnNativeWidgetWindowShowStateChanged() {
+  SaveWindowPlacementIfInitialized();
+}
+
 void Widget::OnNativeWidgetBeginUserBoundsChange() {
   widget_delegate_->OnWindowBeginUserBoundsChange();
 }
@@ -1215,8 +1221,10 @@ void Widget::OnMouseEvent(ui::MouseEvent* event) {
       last_mouse_event_was_move_ = false;
       is_mouse_button_pressed_ = false;
       // Release capture first, to avoid confusion if OnMouseReleased blocks.
-      if (auto_release_capture_ && native_widget_->HasCapture())
+      if (auto_release_capture_ && native_widget_->HasCapture()) {
+        base::AutoReset<bool> resetter(&ignore_capture_loss_, true);
         native_widget_->ReleaseCapture();
+      }
       if (root_view)
         root_view->OnMouseReleased(*event);
       if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0)
@@ -1256,12 +1264,12 @@ void Widget::OnMouseEvent(ui::MouseEvent* event) {
 }
 
 void Widget::OnMouseCaptureLost() {
-  if (is_mouse_button_pressed_ || is_touch_down_) {
-    View* root_view = GetRootView();
-    if (root_view)
-      root_view->OnMouseCaptureLost();
-  }
-  is_touch_down_ = false;
+  if (ignore_capture_loss_)
+    return;
+
+  View* root_view = GetRootView();
+  if (root_view)
+    root_view->OnMouseCaptureLost();
   is_mouse_button_pressed_ = false;
 }
 
@@ -1277,22 +1285,9 @@ void Widget::OnScrollEvent(ui::ScrollEvent* event) {
 }
 
 void Widget::OnGestureEvent(ui::GestureEvent* event) {
-  switch (event->type()) {
-    case ui::ET_GESTURE_TAP_DOWN:
-      is_touch_down_ = true;
-      // We explicitly don't capture here. Not capturing enables multiple
-      // widgets to get tap events at the same time. Views (such as tab
-      // dragging) may explicitly capture.
-      break;
-
-    case ui::ET_GESTURE_END:
-      if (event->details().touch_points() == 1)
-        is_touch_down_ = false;
-      break;
-
-    default:
-      break;
-  }
+  // We explicitly do not capture here. Not capturing enables multiple widgets
+  // to get tap events at the same time. Views (such as tab dragging) may
+  // explicitly capture.
   SendEventToProcessor(event);
 }
 
@@ -1401,6 +1396,12 @@ void Widget::DestroyRootView() {
   input_method_.reset();
 }
 
+void Widget::OnDragWillStart() {
+}
+
+void Widget::OnDragComplete() {
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Widget, private:
 
@@ -1427,6 +1428,11 @@ void Widget::SaveWindowPlacement() {
   widget_delegate_->SaveWindowPlacement(bounds, show_state);
 }
 
+void Widget::SaveWindowPlacementIfInitialized() {
+  if (native_widget_initialized_)
+    SaveWindowPlacement();
+}
+
 void Widget::SetInitialBounds(const gfx::Rect& bounds) {
   if (!non_client_view_)
     return;