/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///<reference path="../../../android/graphics/Paint.ts"/>
///<reference path="../../../android/text/TextPaint.ts"/>
///<reference path="../../../android/text/style/CharacterStyle.ts"/>
///<reference path="../../../android/text/style/UpdateLayout.ts"/>

module android.text.style {
    import Paint = android.graphics.Paint;
    import TextPaint = android.text.TextPaint;
    import CharacterStyle = android.text.style.CharacterStyle;
    import UpdateLayout = android.text.style.UpdateLayout;
    /**
     * The classes that affect character-level text formatting in a way that
     * changes the width or height of characters extend this class.
     */
export abstract class MetricAffectingSpan extends CharacterStyle implements UpdateLayout {
        static type = Symbol();
        mType = MetricAffectingSpan.type;

        abstract updateMeasureState(p:TextPaint):void;

        /**
         * Returns "this" for most MetricAffectingSpans, but for
         * MetricAffectingSpans that were generated by {@link #wrap},
         * returns the underlying MetricAffectingSpan.
         */
        getUnderlying():MetricAffectingSpan {
            return this;
        }


    }

    export module MetricAffectingSpan {
        /* package */
        export class Passthrough_MetricAffectingSpan extends MetricAffectingSpan {

            private mStyle:MetricAffectingSpan;

            /**
             * Creates a new Passthrough of the specfied MetricAffectingSpan.
             */
            constructor(cs:MetricAffectingSpan) {
                super();
                this.mStyle = cs;
            }

            /**
             * Passes updateDrawState through to the underlying MetricAffectingSpan.
             */
            updateDrawState(tp:TextPaint):void {
                this.mStyle.updateDrawState(tp);
            }

            /**
             * Passes updateMeasureState through to the underlying MetricAffectingSpan.
             */
            updateMeasureState(tp:TextPaint):void {
                this.mStyle.updateMeasureState(tp);
            }

            /**
             * Returns the MetricAffectingSpan underlying this one, or the one
             * underlying it if it too is a Passthrough.
             */
            getUnderlying():MetricAffectingSpan {
                return this.mStyle.getUnderlying();
            }
        }
    }

}