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

Side by Side Diff: Source/web/WebViewImpl.cpp

Issue 177903010: Expose the selection root bounds in WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: apply Tim's comments Created 6 years, 9 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 scaledAnchor.scale(pageScaleFactor()); 2137 scaledAnchor.scale(pageScaleFactor());
2138 scaledFocus.scale(pageScaleFactor()); 2138 scaledFocus.scale(pageScaleFactor());
2139 anchor = scaledAnchor; 2139 anchor = scaledAnchor;
2140 focus = scaledFocus; 2140 focus = scaledFocus;
2141 2141
2142 if (!selection.selection().isBaseFirst()) 2142 if (!selection.selection().isBaseFirst())
2143 std::swap(anchor, focus); 2143 std::swap(anchor, focus);
2144 return true; 2144 return true;
2145 } 2145 }
2146 2146
2147 bool WebViewImpl::selectionRootBounds(WebRect& bounds) const
2148 {
2149 const LocalFrame* frame = focusedWebCoreFrame();
2150 if (!frame)
2151 return false;
2152
2153 Element* root = frame->selection().rootEditableElementOrDocumentElement();
2154 if (!root)
2155 return false;
2156
2157 // If the selection is inside a form control, the root will be a <div> that
2158 // behaves as the editor but we want to return the actual element's bounds.
2159 // In practice, that means <textarea> and <input> controls that behave like
2160 // a text field.
2161 if (root->shadowHost()
2162 && (root->shadowHost()->hasTagName(HTMLNames::textareaTag)
2163 || (root->shadowHost()->hasTagName(HTMLNames::inputTag)
2164 && toHTMLInputElement(root->shadowHost())->isText())))
2165 root = root->shadowHost();
2166
2167 IntRect boundingBox = root->pixelSnappedBoundingBox();
2168 boundingBox = root->document().frame()->view()->contentsToWindow(boundingBox );
2169 boundingBox.scale(pageScaleFactor());
2170 bounds = boundingBox;
2171
2172 return true;
2173 }
2174
2147 InputMethodContext* WebViewImpl::inputMethodContext() 2175 InputMethodContext* WebViewImpl::inputMethodContext()
2148 { 2176 {
2149 if (!m_imeAcceptEvents) 2177 if (!m_imeAcceptEvents)
2150 return 0; 2178 return 0;
2151 2179
2152 LocalFrame* focusedFrame = focusedWebCoreFrame(); 2180 LocalFrame* focusedFrame = focusedWebCoreFrame();
2153 if (!focusedFrame) 2181 if (!focusedFrame)
2154 return 0; 2182 return 0;
2155 2183
2156 Element* target = focusedFrame->document()->focusedElement(); 2184 Element* target = focusedFrame->document()->focusedElement();
(...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after
3968 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 3996 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
3969 3997
3970 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 3998 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
3971 return false; 3999 return false;
3972 4000
3973 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4001 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
3974 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4002 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
3975 } 4003 }
3976 4004
3977 } // namespace blink 4005 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | public/web/WebWidget.h » ('j') | public/web/WebWidget.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698