| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\RemexHtml\TreeBuilder; |
| 4 |
|
| 5 |
use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 6 |
|
| 7 |
/** |
| 8 |
* The "in frameset" insertion mode |
| 9 |
*/ |
| 10 |
class InFrameset extends InsertionMode { |
| 11 |
/** @inheritDoc */ |
| 12 |
public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 13 |
$this->handleFramesetWhitespace( false, $text, $start, $length, $sourceStart, $sourceLength ); |
| 14 |
} |
| 15 |
|
| 16 |
/** @inheritDoc */ |
| 17 |
public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 18 |
$builder = $this->builder; |
| 19 |
$dispatcher = $this->dispatcher; |
| 20 |
|
| 21 |
switch ( $name ) { |
| 22 |
case 'html': |
| 23 |
$dispatcher->inBody->startTag( |
| 24 |
$name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 25 |
break; |
| 26 |
|
| 27 |
case 'frameset': |
| 28 |
$builder->insertElement( $name, $attrs, false, $sourceStart, $sourceLength ); |
| 29 |
break; |
| 30 |
|
| 31 |
case 'frame': |
| 32 |
$dispatcher->ack = true; |
| 33 |
$builder->insertElement( $name, $attrs, true, $sourceStart, $sourceLength ); |
| 34 |
break; |
| 35 |
|
| 36 |
case 'noframes': |
| 37 |
$dispatcher->inHead->startTag( |
| 38 |
$name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 39 |
break; |
| 40 |
|
| 41 |
default: |
| 42 |
$builder->error( "unexpected start tag in frameset, ignoring", $sourceStart ); |
| 43 |
return; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** @inheritDoc */ |
| 48 |
public function endTag( $name, $sourceStart, $sourceLength ) { |
| 49 |
$builder = $this->builder; |
| 50 |
$stack = $builder->stack; |
| 51 |
$dispatcher = $this->dispatcher; |
| 52 |
|
| 53 |
switch ( $name ) { |
| 54 |
case 'frameset': |
| 55 |
if ( $stack->current->htmlName === 'html' ) { |
| 56 |
$builder->error( "unexpected </frameset> in fragment context", $sourceStart ); |
| 57 |
return; |
| 58 |
} |
| 59 |
$builder->pop( $sourceStart, $sourceLength ); |
| 60 |
if ( !$builder->isFragment && $stack->current !== 'frameset' ) { |
| 61 |
$dispatcher->switchMode( Dispatcher::AFTER_FRAMESET ); |
| 62 |
} |
| 63 |
break; |
| 64 |
|
| 65 |
default: |
| 66 |
$builder->error( "unexpected </$name> in frameset", $sourceStart ); |
| 67 |
return; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/** @inheritDoc */ |
| 72 |
public function endDocument( $pos ) { |
| 73 |
$builder = $this->builder; |
| 74 |
$stack = $builder->stack; |
| 75 |
|
| 76 |
if ( $stack->current->htmlName !== 'html' ) { |
| 77 |
$builder->error( "unexpected end of file in frameset mode", $pos ); |
| 78 |
} |
| 79 |
|
| 80 |
$builder->stopParsing( $pos ); |
| 81 |
} |
| 82 |
} |