2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: OutputState.C /main/1 1996/07/29 16:59:44 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "OutputState.h"
33 #include "Allocator.h"
36 namespace SP_NAMESPACE {
39 OutputState::OutputState()
45 void OutputState::init()
49 stack_.insert(new OutputStateLevel);
52 OutputStateLevel::OutputStateLevel()
53 : state(OutputState::afterStartTag), reSerial(0)
57 void OutputState::handleRe(EventHandler &handler, Allocator &alloc,
58 const EventsWanted &eventsWanted, Char re,
59 const Location &location)
62 if (eventsWanted.wantInstanceMarkup())
63 handler.reOrigin(new (alloc) ReOriginEvent(re_, location, nextSerial_));
64 switch (top().state) {
66 // it's the first RE in the element
67 if (eventsWanted.wantInstanceMarkup())
68 handler.ignoredRe(new (alloc) IgnoredReEvent(re_, location, nextSerial_++));
69 top().state = afterRsOrRe;
73 top().state = pendingAfterRsOrRe;
74 top().reLocation = location;
75 top().reSerial = nextSerial_++;
77 case pendingAfterRsOrRe:
78 // We now know that the pending RE won't be ignored as the last RE.
79 handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
80 top().state = pendingAfterRsOrRe;
81 top().reLocation = location;
82 top().reSerial = nextSerial_++;
84 case pendingAfterMarkup:
85 // We've had only markup since the last RS or RE, so this
86 // RE is ignored. Note that it's this RE that's ignored, not
88 if (eventsWanted.wantInstanceMarkup())
89 handler.ignoredRe(new (alloc) IgnoredReEvent(re_, location, nextSerial_++));
90 top().state = pendingAfterRsOrRe;
95 void OutputState::noteRs(EventHandler &, Allocator &, const EventsWanted &)
97 if (top().hasPendingRe())
98 top().state = pendingAfterRsOrRe;
100 top().state = afterRsOrRe;
103 void OutputState::noteMarkup(EventHandler &, Allocator &, const EventsWanted &)
105 switch (top().state) {
107 top().state = afterStartTag;
109 case pendingAfterRsOrRe:
110 top().state = pendingAfterMarkup;
113 break; // avoid warning
117 void OutputState::noteData(EventHandler &handler, Allocator &alloc,
118 const EventsWanted &)
120 if (top().hasPendingRe())
121 handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
122 top().state = afterData;
125 void OutputState::noteStartElement(Boolean included,
126 EventHandler &handler, Allocator &alloc,
127 const EventsWanted &)
130 stack_.insert(new OutputStateLevel);
132 if (top().hasPendingRe())
133 handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
134 top().state = afterStartTag;
138 void OutputState::noteEndElement(Boolean included, EventHandler &handler,
140 const EventsWanted &eventsWanted)
142 if (eventsWanted.wantInstanceMarkup() && top().hasPendingRe())
143 handler.ignoredRe(new (alloc) IgnoredReEvent(re_, top().reLocation,
147 noteMarkup(handler, alloc, eventsWanted);
150 top().state = afterData;