View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.event;
16  
17  import org.htmlunit.corejs.javascript.ScriptableObject;
18  import org.htmlunit.javascript.JavaScriptEngine;
19  import org.htmlunit.javascript.configuration.JsxClass;
20  import org.htmlunit.javascript.configuration.JsxConstructor;
21  import org.htmlunit.javascript.configuration.JsxGetter;
22  
23  /**
24   * JavaScript host object for {@code CompositionEvent}.
25   *
26   * @author Ahmed Ashour
27   * @author Ronald Brill
28   *
29   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent">MDN Documentation</a>
30   */
31  @JsxClass
32  public class CompositionEvent extends UIEvent {
33  
34      private String data_;
35  
36      /**
37       * Creates a new event instance.
38       */
39      public CompositionEvent() {
40          super();
41          data_ = "";
42      }
43  
44      /**
45       * Creates an instance of this event.
46       *
47       * @param type the event type
48       * @param details the event details (optional)
49       */
50      @Override
51      @JsxConstructor
52      public void jsConstructor(final String type, final ScriptableObject details) {
53          super.jsConstructor(type, details);
54  
55          if (details != null && !JavaScriptEngine.isUndefined(details)) {
56              final Object dataObj = details.get("data", details);
57              if (NOT_FOUND != dataObj) {
58                  data_ = JavaScriptEngine.toString(dataObj);
59              }
60          }
61      }
62  
63      /**
64       * Returns the composition data.
65       *
66       * @return the data
67       */
68      @JsxGetter
69      public String getData() {
70          return data_;
71      }
72  
73      /**
74       * Sets the composition data.
75       *
76       * @param data the data
77       */
78      public void setData(final String data) {
79          data_ = data;
80      }
81  }