diff --git a/engine/src/flutter/lib/ui/hash_codes.dart b/engine/src/flutter/lib/ui/hash_codes.dart index 033133dae2..bece69b088 100644 --- a/engine/src/flutter/lib/ui/hash_codes.dart +++ b/engine/src/flutter/lib/ui/hash_codes.dart @@ -8,8 +8,8 @@ class _HashEnd { const _HashEnd(); } const _HashEnd _hashEnd = const _HashEnd(); /// Jenkins hash function, optimized for small integers. -/// -/// Borrowed from the dart sdk: sdk/lib/math/jenkins_smi_hash.dart. +// +// Borrowed from the dart sdk: sdk/lib/math/jenkins_smi_hash.dart. class _Jenkins { static int combine(int hash, Object o) { assert(o is! Iterable); @@ -25,18 +25,20 @@ class _Jenkins { } } -/// Combine up to twenty values' hashCodes into one value. +/// Combine up to twenty objects' hash codes into one value. /// -/// If you only need to handle one value's hashCode, then just refer to its -/// [hashCode] getter directly. +/// If you only need to handle one object's hash code, then just refer to its +/// [Object.hashCode] getter directly. /// -/// If you need to combine an arbitrary number of values from a List or other -/// Iterable, use [hashList]. The output of hashList can be used as one of the -/// arguments to this function. +/// If you need to combine an arbitrary number of objects from a [List] or other +/// [Iterable], use [hashList]. The output of [hashList] can be used as one of +/// the arguments to this function. /// /// For example: /// -/// int hashCode => hashValues(foo, bar, hashList(quux), baz); +/// ```dart +/// int hashCode => hashValues(foo, bar, hashList(quux), baz); +/// ``` int hashValues( Object arg01, Object arg02, [ Object arg03 = _hashEnd, Object arg04 = _hashEnd, Object arg05 = _hashEnd, Object arg06 = _hashEnd, @@ -106,14 +108,14 @@ int hashValues( return _Jenkins.finish(result); } -/// Combine the hashCodes of an arbitrary number of values from an Iterable into -/// one value. This function will return the same value if given "null" as if -/// given an empty list. -int hashList(Iterable args) { +/// Combine the [Object.hashCode] values of an arbitrary number of objects from +/// an [Iterable] into one value. This function will return the same value if +/// given null as if given an empty list. +int hashList(Iterable arguments) { int result = 0; - if (args != null) { - for (Object arg in args) - result = _Jenkins.combine(result, arg); + if (arguments != null) { + for (Object argument in arguments) + result = _Jenkins.combine(result, argument); } return _Jenkins.finish(result); } diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index bfd612cc8e..4eb52748c4 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -293,12 +293,12 @@ enum PaintingStyle { // in sync. /// Apply the [Paint] to the inside of the shape. For example, when - /// applied to the [Paint.drawCircle] call, this results in a disc + /// applied to the [Canvas.drawCircle] call, this results in a disc /// of the given size being painted. fill, /// Apply the [Paint] to the edge of the shape. For example, when - /// applied to the [Paint.drawCircle] call, this results is a hoop + /// applied to the [Canvas.drawCircle] call, this results is a hoop /// of the given size being painted. The line drawn on the edge will /// be the width given by the [Paint.strokeWidth] property. stroke, @@ -591,7 +591,7 @@ class Paint { /// To obtain an Image object, use [decodeImageFromList]. /// /// To draw an Image, use one of the methods on the [Canvas] class, such as -/// [drawImage]. +/// [Canvas.drawImage]. abstract class Image extends NativeFieldWrapperClass2 { /// The number of image pixels along the image's horizontal axis. int get width native "Image_width"; @@ -895,7 +895,7 @@ class ColorFilter { /// The output of this filter is then composited into the background according /// to the [Paint.blendMode], using the output of this filter as the source /// and the background as the destination. - ColorFilter.mode(Color color, BlendMode blendMode) + const ColorFilter.mode(Color color, BlendMode blendMode) : _color = color, _blendMode = blendMode; final Color _color; @@ -994,11 +994,11 @@ Float32List _encodeTwoPoints(Offset pointA, Offset pointB) { /// A shader (as used by [Paint.shader]) that renders a color gradient. /// /// There are two useful types of gradients, created by [new Gradient.linear] -/// and [new Griadent.radial]. +/// and [new Gradient.radial]. class Gradient extends Shader { /// Creates a Gradient object that is not initialized. /// - /// Use the [Gradient.linear] or [Gradient.radial] constructors to + /// Use the [new Gradient.linear] or [new Gradient.radial] constructors to /// obtain a usable [Gradient] object. Gradient(); void _constructor() native "Gradient_constructor"; @@ -1150,7 +1150,7 @@ class Vertices extends NativeFieldWrapperClass2 { enum PointMode { /// Draw each point separately. /// - /// If the [Paint.strokeCap] is [StrokeCat.round], then each point is drawn + /// If the [Paint.strokeCap] is [StrokeCap.round], then each point is drawn /// as a circle with the diameter of the [Paint.strokeWidth], filled as /// described by the [Paint] (ignoring [Paint.style]). /// @@ -1527,9 +1527,26 @@ class Canvas extends NativeFieldWrapperClass2 { /// [PictureRecorder]. void drawPicture(Picture picture) native "Canvas_drawPicture"; - /// Draws the text in the given paragraph into this canvas at the given offset. + /// Draws the text in the given [Paragraph] into this canvas at the given + /// [Offset]. /// - /// Valid only after [Paragraph.layout] has been called on the paragraph. + /// The [Paragraph] object must have had [Paragraph.layout] called on it + /// first. + /// + /// To align the text, set the `textAlign` on the [ParagraphStyle] object + /// passed to the [new ParagraphBuilder] constructor. For more details see + /// [TextAlign] and the discussion at [new ParagraphStyle]. + /// + /// If the text is left aligned or justified, the left margin will be at the + /// position specified by the `offset` argument's [Offset.dx] coordinate. + /// + /// If the text is right aligned or justified, the right margin will be at the + /// position described by adding the [ParagraphConstraints.width] given to + /// [Paragraph.layout], to the `offset` argument's [Offset.dx] coordinate. + /// + /// If the text is centered, the centering axis will be at the position + /// described by adding half of the [ParagraphConstraints.width] given to + /// [Paragraph.layout], to the `offset` argument's [Offset.dx] coordinate. void drawParagraph(Paragraph paragraph, Offset offset) { paragraph._paint(this, offset.dx, offset.dy); } diff --git a/engine/src/flutter/lib/ui/semantics.dart b/engine/src/flutter/lib/ui/semantics.dart index 471000a480..cab175aeb7 100644 --- a/engine/src/flutter/lib/ui/semantics.dart +++ b/engine/src/flutter/lib/ui/semantics.dart @@ -7,6 +7,8 @@ part of dart.ui; /// The possible actions that can be conveyed from the operating system /// accessibility APIs to a semantics node. class SemanticsAction { + const SemanticsAction._(this.index); + static const int _kTapIndex = 1 << 0; static const int _kLongPressIndex = 1 << 1; static const int _kScrollLeftIndex = 1 << 2; @@ -16,8 +18,6 @@ class SemanticsAction { static const int _kIncreaseIndex = 1 << 6; static const int _kDecreaseIndex = 1 << 7; - const SemanticsAction._(this.index); - /// The numerical value for this action. /// /// Each action has one bit set in this bit field. @@ -173,10 +173,10 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 { /// /// The `flags` are a bit field of [SemanticsFlags] that apply to this node. /// - /// The `actions` are a bit field of [SemanticsActions] that can be undertaken + /// The `actions` are a bit field of [SemanticsAction]s that can be undertaken /// by this node. If the user wishes to undertake one of these actions on this /// node, the [Window.onSemanticsAction] will be called with `id` and one of - /// the possible [SemanticsActions]. Because the semantics tree is maintained + /// the possible [SemanticsAction]s. Because the semantics tree is maintained /// asynchronously, the [Window.onSemanticsAction] callback might be called /// with an action that is no longer possible. /// diff --git a/engine/src/flutter/lib/ui/text.dart b/engine/src/flutter/lib/ui/text.dart index 21839e0cf5..16fbfea439 100644 --- a/engine/src/flutter/lib/ui/text.dart +++ b/engine/src/flutter/lib/ui/text.dart @@ -81,31 +81,35 @@ class FontWeight { } } -/// Whether to align text horizontally +/// Whether to align text horizontally. enum TextAlign { - /// Align the text on the left edge of the container + /// Align the text on the left edge of the container. left, - /// Align the text on the right edge of the container + /// Align the text on the right edge of the container. right, - /// Align the text in the center of the container + /// Align the text in the center of the container. center, - /// Stretch each line of text to fill the width of the container - justify + /// Stretch lines of text that end with a soft line break to fill the width of + /// the container. + /// + /// Lines that end with hard line breaks are left-aligned. + // TODO(ianh): for rtl, this should presumably change to start-aligned. + justify, } -/// A horizontal line used for aligning text +/// A horizontal line used for aligning text. enum TextBaseline { - // The horizontal line used to align the bottom of glyphs for alphabetic characters + // The horizontal line used to align the bottom of glyphs for alphabetic characters. alphabetic, - // The horizontal line used to align ideographic characters + // The horizontal line used to align ideographic characters. ideographic } -/// A linear decoration to draw near the text +/// A linear decoration to draw near the text. class TextDecoration { const TextDecoration._(this._mask); @@ -424,18 +428,47 @@ Int32List _encodeParagraphStyle(TextAlign textAlign, return result; } -/// An opaque object that determines the position of lines within a paragraph of text. +/// An opaque object that determines the configuration used by +/// [ParagraphBuilder] to position lines within a [Paragraph] of text. class ParagraphStyle { /// Creates a new ParagraphStyle object. /// - /// * `textAlign`: The alignment of the text within the lines of the paragraph. - /// * `fontWeight`: The typeface thickness to use when painting the text (e.g., bold). - /// * `fontStyle`: The typeface variant to use when drawing the letters (e.g., italics). - /// * `maxLines`: The maximum number of lines painted. - /// * `fontFamily`: The name of the font to use when painting the text (e.g., Roboto). - /// * `fontSize`: The size of glyphs (in logical pixels) to use when painting the text. - /// * `lineHeight`: The minimum height of the line boxes, as a multiple of the font size. - /// * `ellipsis`: String used to ellipsize overflowing text. + /// * `textAlign`: The alignment of the text within the lines of the + /// paragraph. If the last line is ellipsized (see `ellipsis` below), the + /// alignment is applied to that line after it has been truncated but before + /// the ellipsis has been added. + // See: https://github.com/flutter/flutter/issues/9819 + /// + /// * `fontWeight`: The typeface thickness to use when painting the text + /// (e.g., bold). + /// + /// * `fontStyle`: The typeface variant to use when drawing the letters (e.g., + /// italics). + /// + /// * `maxLines`: The maximum number of lines painted. Lines beyond this + /// number are silently dropped. For example, if `maxLines` is 1, then only + /// one line is rendered. If `maxLines` is null, but `ellipsis` is not null, + /// then lines after the first one that overflows the width constraints are + /// dropped. The width constraints are those set in the + /// [ParagraphConstraints] object passed to the [Paragraph.layout] method. + /// + /// * `fontFamily`: The name of the font to use when painting the text (e.g., + /// Roboto). + /// + /// * `fontSize`: The size of glyphs (in logical pixels) to use when painting + /// the text. + /// + /// * `lineHeight`: The minimum height of the line boxes, as a multiple of the + /// font size. + /// + /// * `ellipsis`: String used to ellipsize overflowing text. If `maxLines` is + /// not null, then the `ellipsis`, if any, is applied to the last rendered + /// line, if that line overflows the width constraints. If `maxLines` is + /// null, then the `ellipsis` is applied to the first line that overflows + /// the width constraints, and subsequent lines are dropped. The width + /// constraints are those set in the [ParagraphConstraints] object passed to + /// the [Paragraph.layout] method. The empty string and the null value are + /// considered equivalent and turn off this behavior. ParagraphStyle({ TextAlign textAlign, FontWeight fontWeight, @@ -444,7 +477,7 @@ class ParagraphStyle { String fontFamily, double fontSize, double lineHeight, - String ellipsis + String ellipsis, }) : _encoded = _encodeParagraphStyle(textAlign, fontWeight, fontStyle, @@ -504,7 +537,7 @@ enum TextDirection { rtl, /// The text flows from left to right (e.g., English, French). - ltr + ltr, } /// A rectangle enclosing a run of text. @@ -611,6 +644,9 @@ class TextPosition { /// Layout constraints for [Paragraph] objects. /// /// Instances of this class are typically used with [Paragraph.layout]. +/// +/// The only constraint that can be specified is the [width]. See the discussion +/// at [width] for more details. class ParagraphConstraints { /// Creates constraints for laying out a pargraph. /// @@ -623,9 +659,19 @@ class ParagraphConstraints { /// /// If possible, the paragraph will select a soft line break prior to reaching /// this width. If no soft line break is available, the paragraph will select - /// a hard line break prior to reaching this width. + /// a hard line break prior to reaching this width. If that would force a line + /// break without any characters having been placed (i.e. if the next + /// character to be laid out does not fit within the given width constraint) + /// then the next character is allowed to overflow the width constraint and a + /// forced line break is placed after it (even if an explicit line break + /// follows). /// - /// This width will also be used for positioning glyphs with [TextAlign]. + /// The width influences how ellipses are applied. See the discussion at [new + /// ParagraphStyle] for more details. + /// + /// This width is also used to position glyphs according to the [TextAlign] + /// alignment described in the [ParagraphStyle] used when building the + /// [Paragraph] with a [ParagraphBuilder]. final double width; bool operator ==(dynamic other) { @@ -645,15 +691,15 @@ class ParagraphConstraints { /// A paragraph retains the size and position of each glyph in the text and can /// be efficiently resized and painted. /// -/// To create a Paragraph object, use a [ParagraphBuilder]. +/// To create a [Paragraph] object, use a [ParagraphBuilder]. /// -/// Paragraph objects can be displayed on a [Canvas] using the -/// [Canvas.drawParagraph] method. +/// Paragraphs can be displayed on a [Canvas] using the [Canvas.drawParagraph] +/// method. abstract class Paragraph extends NativeFieldWrapperClass2 { /// Creates an uninitialized Paragraph object. /// - /// Calling the Paragraph constructor directly will not create a useable - /// object. To create a Paragraph object, use a [ParagraphBuilder]. + /// Calling the [Paragraph] constructor directly will not create a useable + /// object. To create a [Paragraph] object, use a [ParagraphBuilder]. Paragraph(); // (this constructor is here just so we can document it) /// The amount of horizontal space this paragraph occupies. @@ -686,11 +732,18 @@ abstract class Paragraph extends NativeFieldWrapperClass2 { /// baseline of the first line, in logical pixels. double get ideographicBaseline native "Paragraph_ideographicBaseline"; - /// True if there is more vertical content, but the text was truncated - /// because we reached [ParagraphStyle.maxLines] lines of text. + /// True if there is more vertical content, but the text was truncated, either + /// because we reached `maxLines` lines of text or because the `maxLines` was + /// null, `ellipsis` was not null, and one of the lines exceeded the width + /// constraint. + /// + /// See the discussion of the `maxLines` and `ellipsis` arguments at [new + /// ParagraphStyle]. bool get didExceedMaxLines native "Paragraph_didExceedMaxLines"; /// Computes the size and position of each glyph in the paragraph. + /// + /// The [ParagraphConstraints] control how wide the text is allowed to be. void layout(ParagraphConstraints constraints) => _layout(constraints.width); void _layout(double width) native "Paragraph_layout"; @@ -718,6 +771,19 @@ abstract class Paragraph extends NativeFieldWrapperClass2 { } /// Builds a [Paragraph] containing text with the given styling information. +/// +/// To set the paragraph's alignment, truncation, and ellipsising behavior, pass +/// an appropriately-configured [ParagraphStyle] object to the [new +/// ParagraphBuilder] constructor. +/// +/// Then, call combinations of [pushStyle], [addText], and [pop] to add styled +/// text to the object. +/// +/// Finally, call [build] to obtain the constructed [Paragraph] object. After +/// this point, the builder is no longer usable. +/// +/// After constructing a [Paragraph], call [Paragraph.layout] on it and then +/// paint it with [Canvas.drawParagraph]. class ParagraphBuilder extends NativeFieldWrapperClass2 { /// Creates a [ParagraphBuilder] object, which is used to create a /// [Paragraph]. @@ -743,7 +809,8 @@ class ParagraphBuilder extends NativeFieldWrapperClass2 { /// The text will be styled according to the current stack of text styles. void addText(String text) native "ParagraphBuilder_addText"; - /// Applies the given paragraph style and returns a Paragraph containing the added text and associated styling. + /// Applies the given paragraph style and returns a [Paragraph] containing the + /// added text and associated styling. /// /// After calling this function, the paragraph builder object is invalid and /// cannot be used further. diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index d56bb9e21a..d7f488d86c 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -29,7 +29,7 @@ typedef void PlatformMessageCallback(String name, ByteData data, PlatformMessage enum AppLifecycleState { /// The application is not currently visible to the user. When the /// application is in this state, the engine will not call the - /// [onBeginFrame] callback. + /// [Window.onBeginFrame] callback. paused, /// The application is visible to the user. @@ -41,7 +41,7 @@ enum AppLifecycleState { /// interface, as exposed by [Window.padding]. /// /// For a generic class that represents distances around a rectangle, see the -/// [EdgeDims] class. +/// [EdgeInsets] class. class WindowPadding { const WindowPadding._({ this.left, this.top, this.right, this.bottom }); @@ -173,17 +173,16 @@ class Window { /// times during a single [onBeginFrame] callback or called outside the scope /// of an [onBeginFrame], the call will be ignored. /// - /// To record graphical operations, first create a - /// [PictureRecorder], then construct a [Canvas], passing that - /// [PictureRecorder] to its constructor. After issuing all the - /// graphical operations, call the [endRecording] function on the - /// [PictureRecorder] to obtain the final [Picture] that represents - /// the issued graphical operations. + /// To record graphical operations, first create a [PictureRecorder], then + /// construct a [Canvas], passing that [PictureRecorder] to its constructor. + /// After issuing all the graphical operations, call the + /// [PictureRecorder.endRecording] function on the [PictureRecorder] to obtain + /// the final [Picture] that represents the issued graphical operations. /// /// Next, create a [SceneBuilder], and add the [Picture] to it using - /// [SceneBuilder.addPicture]. With the [SceneBuilder.build] method - /// you can then obtain a [Scene] object, which you can display to - /// the user via this [render] function. + /// [SceneBuilder.addPicture]. With the [SceneBuilder.build] method you can + /// then obtain a [Scene] object, which you can display to the user via this + /// [render] function. void render(Scene scene) native "Window_render"; /// Whether the user has requested that [updateSemantics] be called when