diff options
author | Cary Clark <cary@android.com> | 2010-10-26 10:56:53 -0400 |
---|---|---|
committer | Cary Clark <cary@android.com> | 2010-10-27 11:35:46 -0400 |
commit | af03a3d6830584ef606be2d1c64845815dadb146 (patch) | |
tree | ae2edb24d2deaf62097469d8b1e79b9f4c010b7f /WebCore/platform/graphics/android/LayerAndroid.cpp | |
parent | 43d943757c6b39710fa65034351bc2e84946e8ce (diff) | |
download | external_webkit-af03a3d6830584ef606be2d1c64845815dadb146.zip external_webkit-af03a3d6830584ef606be2d1c64845815dadb146.tar.gz external_webkit-af03a3d6830584ef606be2d1c64845815dadb146.tar.bz2 |
rewrite select text and others for layers
Layers contain pictures, and draw them offset from the top of
the page. Several readers of pictures need to account for this
displacement when computing what part of the picture intersects
a tap on the screen.
The tap may not correspond to the first layer that intersects
it, so all layers must be checked to find the best match. The
root layer usually draws everywhere, so for a match to correspond
to the root, the match must additionally intersect text.
Layers may create offscreen bitmaps when drawing to correctly
alpha blend the results to the screen, but this causes the items
in the bitmap to draw to an unexpected location when the picture
is treated as a spatial database. To get around this, call the
SkCanvas::save() from the overridden saveLayer() to push and
pop the canvas layer state without creating an offscreen.
WebCore/platform/graphics/android/LayerAndroid.cpp
WebCore/platform/graphics/android/LayerAndroid.h
- In find(), iterate through all children, instead of stopping
on the first match.
- Check to see if the child actually draws at the desired location,
and if it draws text there as well.
- Specify a slop factor to allow for inaccuracies in touch.
- Check the root for text before checking the children.
WebKit/android/nav/CachedFrame.cpp
WebKit/android/nav/CachedFrame.h
- Modify the (x,y) co-ordinate by the layer's offset, when
finding the picture corresponding to a point.
WebKit/android/nav/CachedLayer.cpp
WebKit/android/nav/CachedLayer.h
- More plumbing to adjust the point if the picture is contained
in an offset layer.
WebKit/android/nav/CachedRoot.cpp
WebKit/android/nav/CachedRoot.h
- Correct the (x,y) locations by the layer offset.
- Add some debugging (disabled by default)
WebKit/android/nav/ParsedCanvas.h
- One stop shopping that calls save() from saveLayer().
- Reset the bounder to null to balance its ref count.
WebKit/android/nav/SelectText.cpp
WebKit/android/nav/SelectText.h
- Rearrange the way pictures are tracked. Record the picture
corresponding to the input location when the selection starts,
requiring that the picture remain unchanged as the selection
extends.
- Only draw adornments for when the corresponding picture is
drawn. This fixes a Gmail specific problem, where the layers
come and go as the page scrolls.
- Always use the supplied visible bounds instead of computing
it from the canvas.
- Correct location points by layer offsets.
- Add to the picture ref count so it can't be deleted during
selection.
WebKit/android/nav/WebView.cpp
- Simplify visibleRect code.
- Simplify all SelectText interfaces.
bug:3114609
Change-Id: I43dc3252fc86c4b6500edcd650126b2559f530e3
Diffstat (limited to 'WebCore/platform/graphics/android/LayerAndroid.cpp')
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.cpp | 115 |
1 files changed, 105 insertions, 10 deletions
diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index 09fe135..5210171 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -5,8 +5,9 @@ #include "AndroidAnimation.h" #include "DrawExtra.h" +#include "ParseCanvas.h" #include "SkBitmapRef.h" -#include "SkCanvas.h" +#include "SkBounder.h" #include "SkDrawFilter.h" #include "SkPaint.h" #include "SkPicture.h" @@ -251,18 +252,112 @@ void LayerAndroid::clipInner(SkTDArray<SkRect>* region, getChild(i)->clipInner(region, m_haveClip ? localBounds : local); } -const LayerAndroid* LayerAndroid::find(int x, int y) const -{ - for (int i = 0; i < countChildren(); i++) { - const LayerAndroid* found = getChild(i)->find(x, y); - if (found) - return found; +class FindCheck : public SkBounder { +public: + FindCheck() + : m_drew(false) + , m_drewText(false) + { + } + + bool drew() const { return m_drew; } + bool drewText() const { return m_drewText; } + void reset() { m_drew = m_drewText = false; } + +protected: + virtual bool onIRect(const SkIRect& ) + { + m_drew = true; + return false; + } + + virtual bool onIRectGlyph(const SkIRect& , const SkBounder::GlyphRec& ) + { + m_drewText = true; + return false; + } + + bool m_drew; + bool m_drewText; +}; + +class FindCanvas : public ParseCanvas { +public: + void draw(SkPicture* picture, SkScalar offsetX, SkScalar offsetY) + { + save(); + translate(-offsetX, -offsetY); + picture->draw(this); + restore(); + } +}; + +class LayerAndroidFindState { +public: + static const int TOUCH_SLOP = 10; + + LayerAndroidFindState(int x, int y) + : m_x(x) + , m_y(y) + , m_best(0) + { + m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, TOUCH_SLOP * 2, + TOUCH_SLOP * 2); + m_checker.setBounder(&m_findCheck); + m_checker.setBitmapDevice(m_bitmap); + } + + const LayerAndroid* best() const { return m_best; } + + bool drew(SkPicture* picture, const SkRect& localBounds) { + m_findCheck.reset(); + SkScalar localX = SkIntToScalar(m_x - TOUCH_SLOP) - localBounds.fLeft; + SkScalar localY = SkIntToScalar(m_y - TOUCH_SLOP) - localBounds.fTop; + m_checker.draw(picture, localX, localY); + return m_findCheck.drew(); } + + bool drewText() { return m_findCheck.drewText(); } + + void setBest(const LayerAndroid* best) { m_best = best; } + int x() const { return m_x; } + int y() const { return m_y; } + +protected: + int m_x; + int m_y; + const LayerAndroid* m_best; + FindCheck m_findCheck; + SkBitmap m_bitmap; + FindCanvas m_checker; +}; + +void LayerAndroid::findInner(LayerAndroidFindState& state) const +{ + int x = state.x(); + int y = state.y(); + for (int i = 0; i < countChildren(); i++) + getChild(i)->findInner(state); SkRect localBounds; bounds(&localBounds); - if (localBounds.contains(x, y)) - return this; - return 0; + if (!localBounds.contains(x, y)) + return; + if (!m_recordingPicture) + return; + if (!state.drew(m_recordingPicture, localBounds)) + return; + state.setBest(this); // set last match (presumably on top) +} + +const LayerAndroid* LayerAndroid::find(int x, int y, SkPicture* root) const +{ + LayerAndroidFindState state(x, y); + SkRect rootBounds; + rootBounds.setEmpty(); + if (state.drew(root, rootBounds) && state.drewText()) + return 0; // use the root picture only if it contains the text + findInner(state); + return state.best(); } /////////////////////////////////////////////////////////////////////////////// |