From 1a046452f8364930a3a52dd7620f9b7ab7137c31 Mon Sep 17 00:00:00 2001 From: Mangesh Ghiware Date: Wed, 11 Apr 2012 13:40:37 -0700 Subject: Fix crash. Add null checks for m_baseLayer. Refactor common code to a separate getLayerTransform() function that returns a draw tranform ptr. Bug: 6239165 Change-Id: I7c2079e58b49c10a780b099fea9e3d7959b7fe00 --- Source/WebKit/android/nav/WebView.cpp | 43 ++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'Source/WebKit/android/nav/WebView.cpp') diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index 0fcede5..44ad1c5 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -593,6 +593,19 @@ void setTextSelection(SelectText *selection) { setDrawExtra(selection, DrawExtrasSelection); } +const TransformationMatrix* getLayerTransform(int layerId) { + if (layerId != -1 && m_baseLayer) { + LayerAndroid* layer = m_baseLayer->findById(layerId); + // We need to make sure the drawTransform is up to date as this is + // called before a draw() or drawGL() + if (layer) { + m_baseLayer->updateLayerPositions(m_visibleRect); + return layer->drawTransform(); + } + } + return 0; +} + int getHandleLayerId(SelectText::HandleId handleId, SkIPoint& cursorPoint, FloatQuad& textBounds) { SelectText* selectText = static_cast(getDrawExtra(DrawExtrasSelection)); @@ -607,32 +620,20 @@ int getHandleLayerId(SelectText::HandleId handleId, SkIPoint& cursorPoint, textRect.setWidth(std::max(1, textRect.width() - 1)); textBounds = FloatQuad(textRect); - if (layerId != -1) { - // We need to make sure the drawTransform is up to date as this is - // called before a draw() or drawGL() - m_baseLayer->updateLayerPositions(m_visibleRect); - LayerAndroid* root = m_baseLayer; - LayerAndroid* layer = root ? root->findById(layerId) : 0; - if (layer && layer->drawTransform()) { - const TransformationMatrix* transform = layer->drawTransform(); - // We're overloading the concept of Rect to be just the two - // points (bottom-left and top-right. - cursorPoint = transform->mapPoint(cursorPoint); - textBounds = transform->mapQuad(textBounds); - } + const TransformationMatrix* transform = getLayerTransform(layerId); + if (transform) { + // We're overloading the concept of Rect to be just the two + // points (bottom-left and top-right. + cursorPoint = transform->mapPoint(cursorPoint); + textBounds = transform->mapQuad(textBounds); } return layerId; } void mapLayerRect(int layerId, SkIRect& rect) { - if (layerId != -1) { - // We need to make sure the drawTransform is up to date as this is - // called before a draw() or drawGL() - m_baseLayer->updateLayerPositions(m_visibleRect); - LayerAndroid* layer = m_baseLayer ? m_baseLayer->findById(layerId) : 0; - if (layer && layer->drawTransform()) - rect = layer->drawTransform()->mapRect(rect); - } + const TransformationMatrix* transform = getLayerTransform(layerId); + if (transform) + transform->mapRect(rect); } void floatQuadToQuadF(JNIEnv* env, const FloatQuad& nativeTextQuad, -- cgit v1.1