| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/root_view.h" | 5 #include "chrome/views/root_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include "base/base_drag_source.h" | 10 #include "base/base_drag_source.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 Source<View>(child), | 262 Source<View>(child), |
| 263 Details<View>(parent)); | 263 Details<View>(parent)); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 void RootView::SetFocusOnMousePressed(bool f) { | 267 void RootView::SetFocusOnMousePressed(bool f) { |
| 268 focus_on_mouse_pressed_ = f; | 268 focus_on_mouse_pressed_ = f; |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool RootView::OnMousePressed(const MouseEvent& e) { | 271 bool RootView::OnMousePressed(const MouseEvent& e) { |
| 272 static View* last_click_handler = 0; | 272 UpdateCursor(e); |
| 273 | 273 |
| 274 // This function is not to handle non-client messages, so we return that | |
| 275 // we are not handling it quickly except for the double-click because we | |
| 276 // need to absorb it when it occurs on a different view than its single | |
| 277 // click part. | |
| 278 if ((e.GetFlags() & MouseEvent::EF_IS_NON_CLIENT) && | |
| 279 !(e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK)) { | |
| 280 last_click_handler = 0; | |
| 281 return false; | |
| 282 } | |
| 283 | |
| 284 UpdateCursor(e); | |
| 285 SetMouseLocationAndFlags(e); | 274 SetMouseLocationAndFlags(e); |
| 286 | 275 |
| 287 // If mouse_pressed_handler_ is non null, we are currently processing | 276 // If mouse_pressed_handler_ is non null, we are currently processing |
| 288 // a pressed -> drag -> released session. In that case we send the | 277 // a pressed -> drag -> released session. In that case we send the |
| 289 // event to mouse_pressed_handler_ | 278 // event to mouse_pressed_handler_ |
| 290 if (mouse_pressed_handler_) { | 279 if (mouse_pressed_handler_) { |
| 291 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); | 280 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); |
| 292 drag_info.Reset(); | 281 drag_info.Reset(); |
| 293 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, | 282 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, |
| 294 &drag_info); | 283 &drag_info); |
| 295 return true; | 284 return true; |
| 296 } | 285 } |
| 297 DCHECK(!explicit_mouse_handler_); | 286 DCHECK(!explicit_mouse_handler_); |
| 298 | 287 |
| 299 bool hit_disabled_view = false; | 288 bool hit_disabled_view = false; |
| 300 // Walk up the tree until we find a view that wants the mouse event. | 289 // Walk up the tree until we find a view that wants the mouse event. |
| 301 for (mouse_pressed_handler_ = GetViewForPoint(e.location()); | 290 for (mouse_pressed_handler_ = GetViewForPoint(e.location()); |
| 302 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); | 291 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); |
| 303 mouse_pressed_handler_ = mouse_pressed_handler_->GetParent()) { | 292 mouse_pressed_handler_ = mouse_pressed_handler_->GetParent()) { |
| 304 if (!mouse_pressed_handler_->IsEnabled()) { | 293 if (!mouse_pressed_handler_->IsEnabled()) { |
| 305 // Disabled views should eat events instead of propagating them upwards. | 294 // Disabled views should eat events instead of propagating them upwards. |
| 306 hit_disabled_view = true; | 295 hit_disabled_view = true; |
| 307 break; | 296 break; |
| 308 } | 297 } |
| 309 | 298 |
| 310 // See if this view wants to handle the mouse press. | 299 // See if this view wants to handle the mouse press. |
| 311 const MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); | 300 const MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); |
| 312 drag_info.Reset(); | 301 drag_info.Reset(); |
| 313 const bool handled = | 302 const bool handled = |
| 314 (!(e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK) || | |
| 315 (mouse_move_handler_ == last_click_handler)) && | |
| 316 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, | 303 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, |
| 317 &drag_info); | 304 &drag_info); |
| 318 | 305 |
| 319 // The view could have removed itself from the tree when handling | 306 // The view could have removed itself from the tree when handling |
| 320 // OnMousePressed(). In this case, the removal notification will have | 307 // OnMousePressed(). In this case, the removal notification will have |
| 321 // reset mouse_pressed_handler_ to NULL out from under us. Detect this | 308 // reset mouse_pressed_handler_ to NULL out from under us. Detect this |
| 322 // case and stop. (See comments in view.h.) | 309 // case and stop. (See comments in view.h.) |
| 323 // | 310 // |
| 324 // NOTE: Don't return true here, because we don't want the frame to | 311 // NOTE: Don't return true here, because we don't want the frame to |
| 325 // forward future events to us when there's no handler. | 312 // forward future events to us when there's no handler. |
| 326 if (!mouse_pressed_handler_) | 313 if (!mouse_pressed_handler_) |
| 327 break; | 314 break; |
| 328 | 315 |
| 329 // If the view handled the event, leave mouse_pressed_handler_ set and | 316 // If the view handled the event, leave mouse_pressed_handler_ set and |
| 330 // return true, which will cause subsequent drag/release events to get | 317 // return true, which will cause subsequent drag/release events to get |
| 331 // forwarded to that view. | 318 // forwarded to that view. |
| 332 if (handled) { | 319 if (handled) |
| 333 last_click_handler = mouse_pressed_handler_; | |
| 334 return true; | 320 return true; |
| 335 } | |
| 336 } | 321 } |
| 337 | 322 |
| 338 // Reset mouse_pressed_handler_ to indicate that no processing is occurring. | 323 // Reset mouse_pressed_handler_ to indicate that no processing is occurring. |
| 339 mouse_pressed_handler_ = NULL; | 324 mouse_pressed_handler_ = NULL; |
| 340 | 325 |
| 341 if (focus_on_mouse_pressed_) { | 326 if (focus_on_mouse_pressed_) { |
| 342 #if defined(OS_WIN) | 327 #if defined(OS_WIN) |
| 343 HWND hwnd = GetWidget()->GetHWND(); | 328 HWND hwnd = GetWidget()->GetHWND(); |
| 344 if (::GetFocus() != hwnd) { | 329 if (::GetFocus() != hwnd) { |
| 345 ::SetFocus(hwnd); | 330 ::SetFocus(hwnd); |
| 346 } | 331 } |
| 347 #else | 332 #else |
| 348 NOTIMPLEMENTED(); | 333 NOTIMPLEMENTED(); |
| 349 #endif | 334 #endif |
| 350 } | 335 } |
| 351 | |
| 352 // If we go through the whole hierarchy and we did not find the same handler | |
| 353 // for the double-click as we did for the single-click, then mark it as | |
| 354 // handled to eat up any double-click that ends up in a different location | |
| 355 // than its single-click part. | |
| 356 if (last_click_handler && e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK) | |
| 357 hit_disabled_view = true; | |
| 358 | |
| 359 last_click_handler = 0; | |
| 360 return hit_disabled_view; | 336 return hit_disabled_view; |
| 361 } | 337 } |
| 362 | 338 |
| 363 bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, | 339 bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, |
| 364 gfx::Point* p) { | 340 gfx::Point* p) { |
| 365 // | 341 // |
| 366 // If the mouse_handler was set explicitly, we need to keep | 342 // If the mouse_handler was set explicitly, we need to keep |
| 367 // sending events even if it was reparented in a different | 343 // sending events even if it was reparented in a different |
| 368 // window. (a non explicit mouse handler is automatically | 344 // window. (a non explicit mouse handler is automatically |
| 369 // cleared when the control is removed from the hierarchy) | 345 // cleared when the control is removed from the hierarchy) |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 void RootView::SetAccessibleName(const std::wstring& name) { | 946 void RootView::SetAccessibleName(const std::wstring& name) { |
| 971 accessible_name_.assign(name); | 947 accessible_name_.assign(name); |
| 972 } | 948 } |
| 973 | 949 |
| 974 View* RootView::GetDragView() { | 950 View* RootView::GetDragView() { |
| 975 return drag_view_; | 951 return drag_view_; |
| 976 } | 952 } |
| 977 | 953 |
| 978 } // namespace views | 954 } // namespace views |
| 979 | 955 |
| OLD | NEW |