// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;
option java_package = "org.chromium.chrome.browser.autofill_assistant.proto";
option java_multiple_files = true;

package autofill_assistant;

message ViewProto {
  // The unique identifier of the view.
  optional string identifier = 1;

  // Common view attributes, such as padding and background.
  optional ViewAttributesProto attributes = 2;

  // Layout parameters such as width, height, and gravity.
  optional ViewLayoutParamsProto layout_params = 3;

  oneof view {
    ViewContainerProto view_container = 4;
    // A regular read-only text view.
    TextViewProto text_view = 5;
    // A horizontal view divider.
    DividerViewProto divider_view = 6;
    // A regular image view.
    ImageViewProto image_view = 7;
    // A text input view.
    TextInputViewProto text_input_view = 8;
    // A vertical expander with fixed title, collapsed, and expanded sections.
    VerticalExpanderViewProto vertical_expander_view = 9;
    // A toggle button (checkbox or radio button).
    ToggleButtonViewProto toggle_button_view = 10;
  }
}

message ColorProto {
  oneof color {
    // The resource identifier of a color.
    string resource_identifier = 1;
    // A color in the #RRGGBB or #AARRGGBB format.
    string parseable_color = 2;
  }
}

// Represents a dimension, e.g., width or height.
message ClientDimensionProto {
  oneof size {
    int32 dp = 1;
    // Factor to multiply with the client's total width.
    float width_factor = 2;
    // Factor to multiply with the client's total height.
    float height_factor = 3;
  }
}

message ShapeDrawableProto {
  message Rectangle { optional ClientDimensionProto corner_radius = 1; }

  oneof shape { Rectangle rectangle = 1; }
  optional ColorProto background_color = 2;
  optional ClientDimensionProto stroke_width = 3;
  optional ColorProto stroke_color = 4;
}

message BitmapDrawableProto {
  optional string url = 1;
  optional ClientDimensionProto width = 2;
  optional ClientDimensionProto height = 3;
}

// A drawable for use in backgrounds or in image views.
message DrawableProto {
  oneof drawable {
    // The resource identifier of a drawable.
    string resource_identifier = 1;
    // A bitmap retrieved from a URL.
    BitmapDrawableProto bitmap = 2;
    // A shape, e.g., a rounded rectangle.
    ShapeDrawableProto shape = 3;
  }
}

// Attributes of the view.
message ViewAttributesProto {
  optional int32 padding_start = 1;
  optional int32 padding_top = 2;
  optional int32 padding_end = 3;
  optional int32 padding_bottom = 4;

  optional DrawableProto background = 5;
  // The content description for this view. There are three possible states:
  // - unset: content description is auto-inferred by android a11y.
  // - set to empty string: this view is not important for a11y.
  // - set to non-empty string: the view will have the specified content
  // description.
  optional string content_description = 6;
  // Whether the view is initially visible or not.
  optional bool visible = 7 [default = true];
}

// Parameters configuring how views attach to their parents.
message ViewLayoutParamsProto {
  // Enum values map directly to corresponding Android values. This was done for
  // two reasons: (1), for ease-of-implementation and (2) because it is unlikely
  // that any one chosen enum mapping will apply to more than one platform; we
  // might as well match one platform directly.
  enum Gravity {
    UNDEFINED = 0;
    CENTER = 17;
    CENTER_HORIZONTAL = 1;
    CENTER_VERTICAL = 16;
    START = 8388611;
    TOP = 48;
    END = 8388613;
    BOTTOM = 80;
    FILL_HORIZONTAL = 7;
    FILL_VERTICAL = 112;
  }
  enum Size {
    WRAP_CONTENT = -2;
    MATCH_PARENT = -1;
  }

  // The width of the view. Values >= 0 are interpreted as dp. Values < 0
  // are special values as defined in the |Size| enum.
  optional int32 layout_width = 1 [default = -2];
  // The width of the view. Values >= 0 are interpreted as dp.Values < 0
  // are special values as defined in the |Size| enum.
  optional int32 layout_height = 2 [default = -2];
  // The relative weight of the view. Only available in some containers.
  optional float layout_weight = 8;

  optional int32 margin_start = 3;
  optional int32 margin_top = 4;
  optional int32 margin_end = 5;
  optional int32 margin_bottom = 6;

  // A bit-wise OR of the desired |Gravity| values.
  optional int32 layout_gravity = 7;

  // The minimum width of the view, in dp.
  optional int32 minimum_width = 9;

  // The minimum height of the view, in dp.
  optional int32 minimum_height = 10;
}

message ViewContainerProto {
  // The list of views to add to this container.
  repeated ViewProto views = 1;

  oneof container {
    LinearLayoutProto linear_layout = 2;
    VerticalExpanderAccordionProto expander_accordion = 3;
  }
}

message LinearLayoutProto {
  enum Orientation {
    HORIZONTAL = 0;
    VERTICAL = 1;
  }

  optional Orientation orientation = 1;
}

// A vertical expander is a special type of vertical linear layout. It has two
// expansion states (expanded vs. collapsed) and toggles between them by tapping
// the title widget. For user guidance, a chevron is shown in the title to
// indicate the current state.
message VerticalExpanderViewProto {
  enum ChevronStyle {
    // Automatic: will show the chevron only if |expanded_view| is set.
    NOT_SET_AUTOMATIC = 0;
    ALWAYS = 1;
    NEVER = 2;
  }

  // The view to show in the expander title.
  optional ViewProto title_view = 1;

  // The view to show in the collapsed state.
  optional ViewProto collapsed_view = 2;

  // The view to show in the expanded state.
  optional ViewProto expanded_view = 3;

  // The chevron style controls when to show the expand/collapse chevron.
  optional ChevronStyle chevron_style = 4;
}

// This is a special type of linear layout that implements accordion-like
// functionality for all child vertical expanders, i.e., it ensures that at
// most one child vertical expander is expanded at any time.
message VerticalExpanderAccordionProto {
  optional LinearLayoutProto.Orientation orientation = 2;
}

message TextViewProto {
  oneof kind {
    // Static text.
    string text = 1;
    // Dynamic text. Will update automatically to track the value. Should point
    // to a single string value. If specified, view identifier is mandatory!
    string model_identifier = 3;
  }
  optional string text_appearance = 2;
}

message DividerViewProto {}

message ImageViewProto {
  optional DrawableProto image = 1;
}

// A text input widget. Note: View identifier is mandatory!
message TextInputViewProto {
  // This mirrors the type hints specified in
  // https://cs.chromium.org/chromium/src/chrome/android/java/src/org/chromium/chrome/browser/autofill/prefeditor/EditorFieldModel.java
  enum InputTypeHint {
    // No special formatting rules.
    NONE = 0;
    PHONE = 1;
    EMAIL = 2;
    // A multi-line address field that may include numbers.
    STREET_LINES = 3;
    PERSON_NAME = 4;
    // A region or administrative area, e.g., a state or a province.
    REGION = 5;
    ALPHA_NUMERIC = 6;
  }

  // The hint to display when the input is empty.
  optional string hint = 1;
  // A type hint that the widget may interpret to provide optimized controls.
  // Note that the actual impact is version-dependent and not all hints may be
  // supported, in which case a regular text input field will be displayed.
  optional InputTypeHint type = 2;
  // Both input and output. The model identifier containing this view's text.
  // Should point to a single string value.
  optional string model_identifier = 3;
}

// A generic read-only popup message.
message InfoPopupProto {
  // The title of the popup window.
  optional string title = 1;
  // The text of the popup window.
  optional string text = 2;

  message DialogButton {
    message CloseDialog {}
    message OpenUrlInCCT { optional string url = 1; }

    // The action to be executed on click.
    oneof click_action {
      // Closes the popup.
      CloseDialog close_dialog = 4;
      // Opens the specified url into a new CCT.
      OpenUrlInCCT open_url_in_cct = 5;
    }
    optional string label = 1;
  }
  // Optional: adds a positive button.
  optional DialogButton positive_button = 3;
  // Optional: adds a negative button.
  optional DialogButton negative_button = 4;
  // Optional: adds a neutral button.
  optional DialogButton neutral_button = 5;
}

// A toggle button (either a radio button or a check box). Note: view identifier
// is mandatory!
message ToggleButtonViewProto {
  message CheckBox {}
  message RadioButton {
    // This is an arbitrary string that should be shared among all radio buttons
    // belonging to the same exclusion group.
    optional string radio_group_identifier = 1;
  }

  // The type of toggle button.
  oneof kind {
    CheckBox check_box = 1;
    RadioButton radio_button = 2;
  }

  // The view to display to the left of the toggle (if any).
  optional ViewProto left_content_view = 3;

  // The view to display to the right of the toggle (if any).
  optional ViewProto right_content_view = 4;

  // The model identifier to keep in sync with the selection. Should point to a
  // single bool value.
  optional string model_identifier = 5;
}
