OLD | NEW |
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 Loading... |
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_button_pressed_(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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 298 |
297 bool Widget::HasFocusManager() const { | 299 bool Widget::HasFocusManager() const { |
298 return !!focus_manager_.get(); | 300 return !!focus_manager_.get(); |
299 } | 301 } |
300 | 302 |
301 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) { | 303 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) { |
302 GetRootView()->Paint(canvas); | 304 GetRootView()->Paint(canvas); |
303 RefreshCompositeTree(); | 305 RefreshCompositeTree(); |
304 } | 306 } |
305 | 307 |
| 308 bool Widget::OnMouseEvent(const MouseEvent& event) { |
| 309 switch (event.type()) { |
| 310 case ui::ET_MOUSE_PRESSED: |
| 311 last_mouse_event_was_move_ = false; |
| 312 if (GetRootView()->OnMousePressed(event)) { |
| 313 is_mouse_button_pressed_ = true; |
| 314 if (!native_widget_->HasMouseCapture()) |
| 315 native_widget_->SetMouseCapture(); |
| 316 return true; |
| 317 } |
| 318 return false; |
| 319 case ui::ET_MOUSE_RELEASED: |
| 320 last_mouse_event_was_move_ = false; |
| 321 is_mouse_button_pressed_ = false; |
| 322 // Release capture first, to avoid confusion if OnMouseReleased blocks. |
| 323 if (native_widget_->HasMouseCapture() && |
| 324 native_widget_->ShouldReleaseCaptureOnMouseReleased()) { |
| 325 native_widget_->ReleaseMouseCapture(); |
| 326 } |
| 327 GetRootView()->OnMouseReleased(event); |
| 328 return (event.flags() & ui::EF_IS_NON_CLIENT) ? false : true; |
| 329 case ui::ET_MOUSE_MOVED: |
| 330 case ui::ET_MOUSE_DRAGGED: |
| 331 if (native_widget_->HasMouseCapture() && is_mouse_button_pressed_) { |
| 332 last_mouse_event_was_move_ = false; |
| 333 GetRootView()->OnMouseDragged(event); |
| 334 } else if (!last_mouse_event_was_move_ || |
| 335 last_mouse_event_position_ != event.location()) { |
| 336 last_mouse_event_position_ = event.location(); |
| 337 last_mouse_event_was_move_ = true; |
| 338 GetRootView()->OnMouseMoved(event); |
| 339 } |
| 340 return false; |
| 341 case ui::ET_MOUSE_EXITED: |
| 342 last_mouse_event_was_move_ = false; |
| 343 GetRootView()->OnMouseExited(event); |
| 344 return false; |
| 345 default: |
| 346 return false; |
| 347 } |
| 348 return true; |
| 349 } |
| 350 |
| 351 void Widget::OnMouseCaptureLost() { |
| 352 if (is_mouse_button_pressed_) |
| 353 GetRootView()->OnMouseCaptureLost(); |
| 354 is_mouse_button_pressed_ = false; |
| 355 } |
| 356 |
| 357 |
306 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
307 // Widget, FocusTraversable implementation: | 359 // Widget, FocusTraversable implementation: |
308 | 360 |
309 FocusSearch* Widget::GetFocusSearch() { | 361 FocusSearch* Widget::GetFocusSearch() { |
310 return root_view_->GetFocusSearch(); | 362 return root_view_->GetFocusSearch(); |
311 } | 363 } |
312 | 364 |
313 FocusTraversable* Widget::GetFocusTraversableParent() { | 365 FocusTraversable* Widget::GetFocusTraversableParent() { |
314 // We are a proxy to the root view, so we should be bypassed when traversing | 366 // We are a proxy to the root view, so we should be bypassed when traversing |
315 // up and as a result this should not be called. | 367 // up and as a result this should not be called. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // TODO(sad): If there is a parent Widget, then use the same compositor | 421 // TODO(sad): If there is a parent Widget, then use the same compositor |
370 // instead of creating a new one here. | 422 // instead of creating a new one here. |
371 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); | 423 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); |
372 if (widget != gfx::kNullAcceleratedWidget) | 424 if (widget != gfx::kNullAcceleratedWidget) |
373 compositor_ = ui::Compositor::Create(widget); | 425 compositor_ = ui::Compositor::Create(widget); |
374 | 426 |
375 return compositor_.get() != NULL; | 427 return compositor_.get() != NULL; |
376 } | 428 } |
377 | 429 |
378 } // namespace views | 430 } // namespace views |
OLD | NEW |