Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
      6 #define ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
      7 
      8 #include "base/strings/string16.h"
      9 #include "url/gurl.h"
     10 
     11 namespace android_webview {
     12 
     13 // Holdes all hit test data needed by public WebView APIs.
     14 // The Java counter part to this is AwContents.HitTestData.
     15 struct AwHitTestData {
     16 
     17   // Matches exactly with constants in WebView.HitTestResult, with deprecated
     18   // values removed.
     19   enum Type {
     20     // Default type where nothing we are interested in is hit.
     21     // |extra_data_for_type| will be empty. All other values should be emtpy
     22     // except the special case described below.
     23     // For special case of invalid or javascript scheme url that would
     24     // otherwise be type an LINK type, |href| will contain the javascript
     25     // string in the href attribute, and |anchor_text|i and |img_src| contain
     26     // their normal values for the respective type.
     27     UNKNOWN_TYPE = 0,
     28 
     29     // Special case urls for SRC_LINK_TYPE below. Each type corresponds to a
     30     // different prefix in content url_constants. |extra_data_for_type| will
     31     // contain the url but with the prefix removed. |href| will contain the
     32     // exact href attribute string. Other fields are the same as SRC_LINK_TYPE.
     33     PHONE_TYPE = 2,
     34     GEO_TYPE = 3,
     35     EMAIL_TYPE = 4,
     36 
     37     // Hit on a pure image (without links). |extra_data_for_type|, |href|,
     38     // and |anchor_text| will be empty. |img_src| will contain the absolute
     39     // source url of the image.
     40     IMAGE_TYPE = 5,
     41 
     42     // Hit on a link with valid and non-javascript url and without embedded
     43     // image. |extra_data_for_type| and |href| will be the valid absolute url
     44     // of the link. |anchor_text| will contain the anchor text if the link is
     45     // an anchor tag. |img_src| will be empty.
     46     // Note 1: If the link url is invalid or javascript scheme, then the type
     47     // will be UNKNOWN_TYPE.
     48     // Note 2: Note that this matches SRC_ANCHOR_TYPE in the public WebView
     49     // Java API, but the actual tag can be something other than <a>, such as
     50     // <link> or <area>.
     51     // Note 3: |href| is not the raw attribute string, but the absolute link
     52     // url.
     53     SRC_LINK_TYPE = 7,
     54 
     55     // Same as SRC_LINK_TYPE except the link contains an image. |img_src| and
     56     // |extra_data_for_type| will contain the absolute valid url of the image
     57     // source. |href| will be the valid absolute url of the link. |anchor_text|
     58     // will be empty. All notes from SRC_LINK_TYPE apply.
     59     SRC_IMAGE_LINK_TYPE = 8,
     60 
     61     // Hit on an editable text input element. All other values will be empty.
     62     EDIT_TEXT_TYPE = 9,
     63   };
     64 
     65   // For all strings/GURLs, empty/invalid will become null upon conversion to
     66   // Java.
     67   int type;  // Only values from enum Type above.
     68   std::string extra_data_for_type;
     69   string16 href;
     70   string16 anchor_text;
     71   GURL img_src;
     72 
     73   AwHitTestData();
     74   ~AwHitTestData();
     75 };
     76 
     77 }  // namespace android_webview
     78 
     79 #endif  // ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
     80