Adam Barth 21d7575716 Add Paragraph#getPositionForOffset
We'll use this function to position the caret when the user taps a text
input control.

Very little of the code in this patch is actually new. Most of it is
restoring code that we previously removed from the engine. I've made
some small changes to the restored code to handle the lack of a DOM. The
only major change is to RenderObject::createPositionWithAffinity, which
now just returns the values it captures instead of trying to compute a
DOM position.

TextAffinity and TextPosition are lifted from package:flutter. Once this
patch rolls into package:flutter, I'll remove the declarations there.
2016-01-29 23:07:51 -08:00

75 lines
2.2 KiB
C++

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_TEXT_PARAGRAPH_H_
#define SKY_ENGINE_CORE_TEXT_PARAGRAPH_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/rendering/RenderView.h"
#include "sky/engine/core/text/TextBox.h"
namespace blink {
class DartLibraryNatives;
class Paragraph : public RefCounted<Paragraph>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<Paragraph> create(PassOwnPtr<RenderView> renderView) {
return adoptRef(new Paragraph(renderView));
}
~Paragraph() override;
double minWidth() { return m_minWidth; }
void setMinWidth(double width) { m_minWidth = width; }
double maxWidth() { return m_maxWidth; }
void setMaxWidth(double width) { m_maxWidth = width; }
double minHeight() { return m_minHeight; }
void setMinHeight(double height) { m_minHeight = height; }
double maxHeight() { return m_maxHeight; }
void setMaxHeight(double height) { m_maxHeight = height; }
double width();
double height();
double minIntrinsicWidth();
double maxIntrinsicWidth();
double alphabeticBaseline();
double ideographicBaseline();
void layout();
void paint(Canvas* canvas, const Offset& offset);
std::vector<TextBox> getRectsForRange(unsigned start, unsigned end);
Dart_Handle getPositionForOffset(const Offset& offset);
RenderView* renderView() const { return m_renderView.get(); }
static void RegisterNatives(DartLibraryNatives* natives);
private:
RenderBox* firstChildBox() const { return m_renderView->firstChildBox(); }
int absoluteOffsetForPosition(const PositionWithAffinity& position);
LayoutUnit m_minWidth;
LayoutUnit m_maxWidth;
LayoutUnit m_minHeight;
LayoutUnit m_maxHeight;
explicit Paragraph(PassOwnPtr<RenderView> renderView);
OwnPtr<RenderView> m_renderView;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_TEXT_PARAGRAPH_H_