Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: views/widget/widget.cc

Issue 6756043: Consolidate Widget Event code, other cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Consolidate Widget Event code, other cleanup. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/widget/widget.h" 5 #include "views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "ui/gfx/compositor/compositor.h" 9 #include "ui/gfx/compositor/compositor.h"
10 #include "views/focus/view_storage.h" 10 #include "views/focus/view_storage.h"
(...skipping 29 matching lines...) Expand all
40 delete_on_destroy(true), 40 delete_on_destroy(true),
41 mirror_origin_in_rtl(true), 41 mirror_origin_in_rtl(true),
42 has_dropshadow(false), 42 has_dropshadow(false),
43 native_widget(NULL) { 43 native_widget(NULL) {
44 } 44 }
45 45
46 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
47 // Widget, public: 47 // Widget, public:
48 48
49 Widget::Widget() 49 Widget::Widget()
50 : native_widget_(NULL), 50 : is_mouse_down_(false),
51 last_mouse_event_was_move_(false),
52 native_widget_(NULL),
51 widget_delegate_(NULL), 53 widget_delegate_(NULL),
52 dragged_view_(NULL) { 54 dragged_view_(NULL) {
53 } 55 }
54 56
55 Widget::~Widget() { 57 Widget::~Widget() {
56 } 58 }
57 59
58 // Unconverted methods (see header) -------------------------------------------- 60 // Unconverted methods (see header) --------------------------------------------
59 61
60 void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) { 62 void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // dialog). When gtk_widget_destroy is called on the parent, the destroy 341 // dialog). When gtk_widget_destroy is called on the parent, the destroy
340 // signal reaches parent first and then the child. Thus causing the parent 342 // signal reaches parent first and then the child. Thus causing the parent
341 // WidgetGtk's dtor executed before the child's. If child's view hierarchy 343 // WidgetGtk's dtor executed before the child's. If child's view hierarchy
342 // references this focus manager, it crashes. This will defer focus manager's 344 // references this focus manager, it crashes. This will defer focus manager's
343 // destruction after child WidgetGtk's dtor. 345 // destruction after child WidgetGtk's dtor.
344 FocusManager* focus_manager = focus_manager_.release(); 346 FocusManager* focus_manager = focus_manager_.release();
345 if (focus_manager) 347 if (focus_manager)
346 MessageLoop::current()->DeleteSoon(FROM_HERE, focus_manager); 348 MessageLoop::current()->DeleteSoon(FROM_HERE, focus_manager);
347 } 349 }
348 350
351 bool Widget::ProcessMousePressed(const MouseEvent& event) {
352 last_mouse_event_was_move_ = false;
353 if (GetRootView()->OnMousePressed(event)) {
354 is_mouse_down_ = true;
355 if (!native_widget_->HasMouseCapture())
356 native_widget_->SetMouseCapture();
357 return true;
358 }
359 return false;
360 }
361
362 bool Widget::ProcessMouseReleased(const MouseEvent& event) {
363 last_mouse_event_was_move_ = false;
364 is_mouse_down_ = false;
365
366 // Release capture first, to avoid confusion if OnMouseReleased blocks.
367 if (native_widget_->HasMouseCapture() &&
368 native_widget_->ShouldReleaseCaptureOnMouseReleased()) {
369 native_widget_->ReleaseMouseCapture();
370 }
371
372 GetRootView()->OnMouseReleased(event);
373 return true;
374 }
375
376 void Widget::ProcessMouseMoved(const MouseEvent& event) {
377 if (native_widget_->HasMouseCapture() && is_mouse_down_) {
378 last_mouse_event_was_move_ = false;
379 GetRootView()->OnMouseDragged(event);
380 } else if (!last_mouse_event_was_move_ ||
381 last_mouse_event_position_ != event.location()) {
382 last_mouse_event_position_ = event.location();
383 last_mouse_event_was_move_ = true;
384 GetRootView()->OnMouseMoved(event);
385 }
386 }
387
388 void Widget::ProcessMouseCaptureLost() {
389 if (is_mouse_down_)
390 GetRootView()->OnMouseCaptureLost();
391 is_mouse_down_ = false;
392 }
393
349 void Widget::ReplaceFocusManager(FocusManager* focus_manager) { 394 void Widget::ReplaceFocusManager(FocusManager* focus_manager) {
350 focus_manager_.reset(focus_manager); 395 focus_manager_.reset(focus_manager);
351 } 396 }
352 397
353 //////////////////////////////////////////////////////////////////////////////// 398 ////////////////////////////////////////////////////////////////////////////////
354 // Widget, private: 399 // Widget, private:
355 400
356 void Widget::RefreshCompositeTree() { 401 void Widget::RefreshCompositeTree() {
357 if (!EnsureCompositor()) 402 if (!EnsureCompositor())
358 return; 403 return;
(...skipping 10 matching lines...) Expand all
369 // TODO(sad): If there is a parent Widget, then use the same compositor 414 // TODO(sad): If there is a parent Widget, then use the same compositor
370 // instead of creating a new one here. 415 // instead of creating a new one here.
371 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); 416 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget();
372 if (widget != gfx::kNullAcceleratedWidget) 417 if (widget != gfx::kNullAcceleratedWidget)
373 compositor_ = ui::Compositor::Create(widget); 418 compositor_ = ui::Compositor::Create(widget);
374 419
375 return compositor_.get() != NULL; 420 return compositor_.get() != NULL;
376 } 421 }
377 422
378 } // namespace views 423 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698