15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace android_webview {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Holdes all hit test data needed by public WebView APIs.
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The Java counter part to this is AwContents.HitTestData.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct AwHitTestData {
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Matches exactly with constants in WebView.HitTestResult, with deprecated
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // values removed.
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Type {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Default type where nothing we are interested in is hit.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // |extra_data_for_type| will be empty. All other values should be emtpy
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // except the special case described below.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // For special case of invalid or javascript scheme url that would
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // otherwise be type an LINK type, |href| will contain the javascript
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // string in the href attribute, and |anchor_text|i and |img_src| contain
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // their normal values for the respective type.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNKNOWN_TYPE = 0,
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Special case urls for SRC_LINK_TYPE below. Each type corresponds to a
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // different prefix in content url_constants. |extra_data_for_type| will
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // contain the url but with the prefix removed. |href| will contain the
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // exact href attribute string. Other fields are the same as SRC_LINK_TYPE.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PHONE_TYPE = 2,
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GEO_TYPE = 3,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EMAIL_TYPE = 4,
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Hit on a pure image (without links). |extra_data_for_type|, |href|,
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // and |anchor_text| will be empty. |img_src| will contain the absolute
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // source url of the image.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IMAGE_TYPE = 5,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Hit on a link with valid and non-javascript url and without embedded
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // image. |extra_data_for_type| and |href| will be the valid absolute url
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // of the link. |anchor_text| will contain the anchor text if the link is
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // an anchor tag. |img_src| will be empty.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Note 1: If the link url is invalid or javascript scheme, then the type
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // will be UNKNOWN_TYPE.
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Note 2: Note that this matches SRC_ANCHOR_TYPE in the public WebView
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Java API, but the actual tag can be something other than <a>, such as
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // <link> or <area>.
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Note 3: |href| is not the raw attribute string, but the absolute link
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // url.
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SRC_LINK_TYPE = 7,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Same as SRC_LINK_TYPE except the link contains an image. |img_src| and
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // |extra_data_for_type| will contain the absolute valid url of the image
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // source. |href| will be the valid absolute url of the link. |anchor_text|
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // will be empty. All notes from SRC_LINK_TYPE apply.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SRC_IMAGE_LINK_TYPE = 8,
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Hit on an editable text input element. All other values will be empty.
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EDIT_TEXT_TYPE = 9,
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For all strings/GURLs, empty/invalid will become null upon conversion to
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Java.
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int type;  // Only values from enum Type above.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string extra_data_for_type;
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 href;
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 anchor_text;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL img_src;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AwHitTestData();
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~AwHitTestData();
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace android_webview
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
80