| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 6 * Copyright (C) 2015 Google Inc. All rights reserved. | 6 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 inner_node, CreateVisibleSelection( | 312 inner_node, CreateVisibleSelection( |
| 313 SelectionInFlatTree::Builder() | 313 SelectionInFlatTree::Builder() |
| 314 .Collapse(visible_pos.ToPositionWithAffinity()) | 314 .Collapse(visible_pos.ToPositionWithAffinity()) |
| 315 .Build())), | 315 .Build())), |
| 316 kCharacterGranularity, | 316 kCharacterGranularity, |
| 317 is_handle_visible ? HandleVisibility::kVisible | 317 is_handle_visible ? HandleVisibility::kVisible |
| 318 : HandleVisibility::kNotVisible); | 318 : HandleVisibility::kNotVisible); |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| 321 | 321 |
| 322 static bool TargetPositionIsBeforeDragStartPosition( | |
| 323 Node* drag_start_node, | |
| 324 const LayoutPoint& drag_start_point, | |
| 325 Node* target, | |
| 326 const LayoutPoint& hit_test_point) { | |
| 327 const PositionInFlatTree& target_position = | |
| 328 ToPositionInFlatTree(target->GetLayoutObject() | |
| 329 ->PositionForPoint(hit_test_point) | |
| 330 .GetPosition()); | |
| 331 const PositionInFlatTree& drag_start_position = | |
| 332 ToPositionInFlatTree(drag_start_node->GetLayoutObject() | |
| 333 ->PositionForPoint(drag_start_point) | |
| 334 .GetPosition()); | |
| 335 | |
| 336 return target_position.CompareTo(drag_start_position) < 0; | |
| 337 } | |
| 338 | |
| 339 static SelectionInFlatTree ApplySelectAll( | |
| 340 const PositionInFlatTree& base_position, | |
| 341 const PositionInFlatTree& target_position, | |
| 342 Node* mouse_press_node, | |
| 343 const LayoutPoint& drag_start_point, | |
| 344 Node* target, | |
| 345 const LayoutPoint& hit_test_point) { | |
| 346 Node* const root_user_select_all_for_mouse_press_node = | |
| 347 EditingInFlatTreeStrategy::RootUserSelectAllForNode(mouse_press_node); | |
| 348 Node* const root_user_select_all_for_target = | |
| 349 EditingInFlatTreeStrategy::RootUserSelectAllForNode(target); | |
| 350 | |
| 351 if (root_user_select_all_for_mouse_press_node && | |
| 352 root_user_select_all_for_mouse_press_node == | |
| 353 root_user_select_all_for_target) { | |
| 354 return SelectionInFlatTree::Builder() | |
| 355 .SetBaseAndExtent(PositionInFlatTree::BeforeNode( | |
| 356 *root_user_select_all_for_mouse_press_node), | |
| 357 PositionInFlatTree::AfterNode( | |
| 358 *root_user_select_all_for_mouse_press_node)) | |
| 359 .Build(); | |
| 360 } | |
| 361 | |
| 362 SelectionInFlatTree::Builder builder; | |
| 363 // Reset base for user select all when base is inside user-select-all area | |
| 364 // and extent < base. | |
| 365 if (root_user_select_all_for_mouse_press_node && | |
| 366 TargetPositionIsBeforeDragStartPosition( | |
| 367 mouse_press_node, drag_start_point, target, hit_test_point)) { | |
| 368 builder.Collapse(PositionInFlatTree::AfterNode( | |
| 369 *root_user_select_all_for_mouse_press_node)); | |
| 370 } else { | |
| 371 builder.Collapse(base_position); | |
| 372 } | |
| 373 | |
| 374 if (root_user_select_all_for_target && mouse_press_node->GetLayoutObject()) { | |
| 375 if (TargetPositionIsBeforeDragStartPosition( | |
| 376 mouse_press_node, drag_start_point, target, hit_test_point)) { | |
| 377 builder.Extend( | |
| 378 PositionInFlatTree::BeforeNode(*root_user_select_all_for_target)); | |
| 379 return builder.Build(); | |
| 380 } | |
| 381 | |
| 382 builder.Extend( | |
| 383 PositionInFlatTree::AfterNode(*root_user_select_all_for_target)); | |
| 384 return builder.Build(); | |
| 385 } | |
| 386 | |
| 387 builder.Extend(target_position); | |
| 388 return builder.Build(); | |
| 389 } | |
| 390 | |
| 391 // Returns true if selection starts from |SVGText| node and |target_node| is | 322 // Returns true if selection starts from |SVGText| node and |target_node| is |
| 392 // not the containing block of |SVGText| node. | 323 // not the containing block of |SVGText| node. |
| 393 // See https://bugs.webkit.org/show_bug.cgi?id=12334 for details. | 324 // See https://bugs.webkit.org/show_bug.cgi?id=12334 for details. |
| 394 static bool ShouldRespectSVGTextBoundaries( | 325 static bool ShouldRespectSVGTextBoundaries( |
| 395 const Node& target_node, | 326 const Node& target_node, |
| 396 const FrameSelection& frame_selection) { | 327 const FrameSelection& frame_selection) { |
| 397 const PositionInFlatTree& base = | 328 const PositionInFlatTree& base = |
| 398 frame_selection.ComputeVisibleSelectionInFlatTree().Base(); | 329 frame_selection.ComputeVisibleSelectionInFlatTree().Base(); |
| 399 // TODO(editing-dev): We should use |ComputeContainerNode()|. | 330 // TODO(editing-dev): We should use |ComputeContainerNode()|. |
| 400 const Node* const base_node = base.AnchorNode(); | 331 const Node* const base_node = base.AnchorNode(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return; | 376 return; |
| 446 | 377 |
| 447 if (selection_state_ == SelectionState::kHaveNotStartedSelection && | 378 if (selection_state_ == SelectionState::kHaveNotStartedSelection && |
| 448 DispatchSelectStart(target) != DispatchEventResult::kNotCanceled) | 379 DispatchSelectStart(target) != DispatchEventResult::kNotCanceled) |
| 449 return; | 380 return; |
| 450 | 381 |
| 451 // TODO(yosin) We should check |mousePressNode|, |targetPosition|, and | 382 // TODO(yosin) We should check |mousePressNode|, |targetPosition|, and |
| 452 // |newSelection| are valid for |m_frame->document()|. | 383 // |newSelection| are valid for |m_frame->document()|. |
| 453 // |dispatchSelectStart()| can change them by "selectstart" event handler. | 384 // |dispatchSelectStart()| can change them by "selectstart" event handler. |
| 454 | 385 |
| 386 const bool should_extend_selection = |
| 387 selection_state_ == SelectionState::kExtendedSelection; |
| 455 // Always extend selection here because it's caused by a mouse drag | 388 // Always extend selection here because it's caused by a mouse drag |
| 456 const PositionInFlatTree base_position = | |
| 457 selection_state_ == SelectionState::kExtendedSelection | |
| 458 ? Selection().ComputeVisibleSelectionInFlatTree().Base() | |
| 459 : target_position.DeepEquivalent(); | |
| 460 selection_state_ = SelectionState::kExtendedSelection; | 389 selection_state_ = SelectionState::kExtendedSelection; |
| 461 if (base_position.IsNull()) | |
| 462 return; | |
| 463 | 390 |
| 464 const SelectionInFlatTree& applied_selection = ApplySelectAll( | 391 const VisibleSelectionInFlatTree& visible_selection = |
| 465 base_position, target_position.DeepEquivalent(), mouse_press_node, | 392 Selection().ComputeVisibleSelectionInFlatTree(); |
| 466 drag_start_pos, target, hit_test_result.LocalPoint()); | 393 const PositionInFlatTree& adjusted_position = |
| 467 SelectionInFlatTree::Builder builder(applied_selection); | 394 AdjustPositionRespectUserSelectAll(target, visible_selection.Start(), |
| 395 visible_selection.End(), |
| 396 target_position.DeepEquivalent()); |
| 397 const SelectionInFlatTree& adjusted_selection = |
| 398 should_extend_selection |
| 399 ? ExtendSelectionAsDirectional(adjusted_position, visible_selection, |
| 400 Selection().Granularity()) |
| 401 : SelectionInFlatTree::Builder().Collapse(adjusted_position).Build(); |
| 468 | 402 |
| 469 if (Selection().Granularity() != kCharacterGranularity) | 403 SetNonDirectionalSelectionIfNeeded( |
| 470 builder.SetGranularity(Selection().Granularity()); | 404 adjusted_selection, Selection().Granularity(), |
| 471 | 405 kAdjustEndpointsAtBidiBoundary, HandleVisibility::kNotVisible); |
| 472 SetNonDirectionalSelectionIfNeeded(builder.Build(), Selection().Granularity(), | |
| 473 kAdjustEndpointsAtBidiBoundary, | |
| 474 HandleVisibility::kNotVisible); | |
| 475 } | 406 } |
| 476 | 407 |
| 477 bool SelectionController::UpdateSelectionForMouseDownDispatchingSelectStart( | 408 bool SelectionController::UpdateSelectionForMouseDownDispatchingSelectStart( |
| 478 Node* target_node, | 409 Node* target_node, |
| 479 const SelectionInFlatTree& selection, | 410 const SelectionInFlatTree& selection, |
| 480 TextGranularity granularity, | 411 TextGranularity granularity, |
| 481 HandleVisibility handle_visibility) { | 412 HandleVisibility handle_visibility) { |
| 482 if (target_node && target_node->GetLayoutObject() && | 413 if (target_node && target_node->GetLayoutObject() && |
| 483 !target_node->GetLayoutObject()->IsSelectable()) | 414 !target_node->GetLayoutObject()->IsSelectable()) |
| 484 return false; | 415 return false; |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 | 1183 |
| 1253 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { | 1184 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 1254 bool is_mouse_down_on_link_or_image = | 1185 bool is_mouse_down_on_link_or_image = |
| 1255 event.IsOverLink() || event.GetHitTestResult().GetImage(); | 1186 event.IsOverLink() || event.GetHitTestResult().GetImage(); |
| 1256 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != | 1187 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != |
| 1257 0 && | 1188 0 && |
| 1258 !is_mouse_down_on_link_or_image; | 1189 !is_mouse_down_on_link_or_image; |
| 1259 } | 1190 } |
| 1260 | 1191 |
| 1261 } // namespace blink | 1192 } // namespace blink |
| OLD | NEW |