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

Side by Side Diff: third_party/WebKit/Source/core/editing/SelectionModifier.cpp

Issue 2926823002: Introduce LocalCaretRect for refactoring Local{Caret,Selection}RectPosition() (Closed)
Patch Set: 2017-06-09T15:11:53 Created 3 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 return true; 795 return true;
796 } 796 }
797 797
798 // Abs x/y position of the caret ignoring transforms. 798 // Abs x/y position of the caret ignoring transforms.
799 // TODO(yosin) navigation with transforms should be smarter. 799 // TODO(yosin) navigation with transforms should be smarter.
800 static LayoutUnit LineDirectionPointForBlockDirectionNavigationOf( 800 static LayoutUnit LineDirectionPointForBlockDirectionNavigationOf(
801 const VisiblePosition& visible_position) { 801 const VisiblePosition& visible_position) {
802 if (visible_position.IsNull()) 802 if (visible_position.IsNull())
803 return LayoutUnit(); 803 return LayoutUnit();
804 804
805 LayoutObject* layout_object; 805 const LocalCaretRect& caret_rect =
806 LayoutRect local_rect = LocalCaretRectOfPosition( 806 LocalCaretRectOfPosition(visible_position.ToPositionWithAffinity());
807 visible_position.ToPositionWithAffinity(), layout_object); 807 if (caret_rect.IsEmpty())
808 if (local_rect.IsEmpty() || !layout_object)
809 return LayoutUnit(); 808 return LayoutUnit();
810 809
811 // This ignores transforms on purpose, for now. Vertical navigation is done 810 // This ignores transforms on purpose, for now. Vertical navigation is done
812 // without consulting transforms, so that 'up' in transformed text is 'up' 811 // without consulting transforms, so that 'up' in transformed text is 'up'
813 // relative to the text, not absolute 'up'. 812 // relative to the text, not absolute 'up'.
814 FloatPoint caret_point = 813 const FloatPoint& caret_point = caret_rect.layout_object->LocalToAbsolute(
815 layout_object->LocalToAbsolute(FloatPoint(local_rect.Location())); 814 FloatPoint(caret_rect.rect.Location()));
816 LayoutObject* containing_block = layout_object->ContainingBlock(); 815 LayoutObject* const containing_block =
817 if (!containing_block) { 816 caret_rect.layout_object->ContainingBlock();
818 // Just use ourselves to determine the writing mode if we have no containing 817 // Just use ourselves to determine the writing mode if we have no containing
819 // block. 818 // block.
820 containing_block = layout_object; 819 LayoutObject* const layout_object =
821 } 820 containing_block ? containing_block : caret_rect.layout_object;
822 return LayoutUnit(containing_block->IsHorizontalWritingMode() 821 return LayoutUnit(layout_object->IsHorizontalWritingMode() ? caret_point.X()
823 ? caret_point.X() 822 : caret_point.Y());
824 : caret_point.Y());
825 } 823 }
826 824
827 LayoutUnit SelectionModifier::LineDirectionPointForBlockDirectionNavigation( 825 LayoutUnit SelectionModifier::LineDirectionPointForBlockDirectionNavigation(
828 EPositionType type) { 826 EPositionType type) {
829 LayoutUnit x; 827 LayoutUnit x;
830 828
831 if (selection_.IsNone()) 829 if (selection_.IsNone())
832 return x; 830 return x;
833 831
834 Position pos; 832 Position pos;
(...skipping 26 matching lines...) Expand all
861 x = LineDirectionPointForBlockDirectionNavigationOf(visible_position); 859 x = LineDirectionPointForBlockDirectionNavigationOf(visible_position);
862 x_pos_for_vertical_arrow_navigation_ = x; 860 x_pos_for_vertical_arrow_navigation_ = x;
863 } else { 861 } else {
864 x = x_pos_for_vertical_arrow_navigation_; 862 x = x_pos_for_vertical_arrow_navigation_;
865 } 863 }
866 864
867 return x; 865 return x;
868 } 866 }
869 867
870 } // namespace blink 868 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698