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),
// 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;
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.
dragged_view_ = NULL;
view->OnDragDone();
}
+ OnDragComplete();
}
void Widget::SchedulePaintInRect(const gfx::Rect& rect) {
}
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() {
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();
}
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)
}
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;
}
}
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);
}
input_method_.reset();
}
+void Widget::OnDragWillStart() {
+}
+
+void Widget::OnDragComplete() {
+}
+
////////////////////////////////////////////////////////////////////////////////
// Widget, private:
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;