// Copyright 2010-2020, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Protocol messages to be used for mozc client/renderer communication.
//
// The RendererCommand message contains all the rendering informatioin
// sent from client to renderer.  The messages structure of
// RendererCommand and its child messages are here:

syntax = "proto2";

package mozc.commands;

import "protocol/commands.proto";

message RendererCommand {
  message Rectangle {
    optional int32 left = 1;
    optional int32 top = 2;
    optional int32 right = 3;
    optional int32 bottom = 4;
  }
  message Point {
    optional int32 x = 1;
    optional int32 y = 2;
  }

  enum CommandType {
    NOOP = 0;      // No operation
    UPDATE = 1;    // Update the current window
    SHUTDOWN = 2;  // shutdown renderer
  }

  optional CommandType type = 1 [default = NOOP];

  // set visibility
  // if visible is false, the content of output
  // is basically ignored.
  optional bool visible = 2 [default = false];

  optional Output output = 3;

  // Preedit rectangle
  optional Rectangle preedit_rectangle = 4;

  // TODO(yukawa): make a common font format for all platforms.
  message WinLogFont {
    optional int32 height = 1 [default = 0];
    optional int32 width = 2 [default = 0];
    optional int32 escapement = 3 [default = 0];
    optional int32 orientation = 4 [default = 0];
    optional int32 weight = 5 [default = 0];  // FW_DONTCARE
    optional bool italic = 6 [default = false];
    optional bool underline = 7 [default = false];
    optional bool strike_out = 8 [default = false];
    optional int32 char_set = 9 [default = 1];           // DEFAULT_CHARSET
    optional int32 out_precision = 10 [default = 0];     // OUT_DEFAULT_PRECIS
    optional int32 clip_precision = 11 [default = 0];    // CLIP_DEFAULT_PRECIS
    optional int32 quality = 12 [default = 0];           // DEFAULT_QUALITY
    optional int32 pitch_and_family = 13 [default = 0];  // DEFAULT_PITCH
    optional string face_name = 14;  // should be within 32 TCHARs (w/ '\0')
  }

  // An equivalent to COMPOSITIONFORM in IMM32. (For Windows only)
  // TODO(yukawa): make a common composition form format for all platforms.
  message CompositionForm {
    reserved 1;
    reserved "style";
    optional Point current_position = 2;
    optional Rectangle area = 3;
    // Used as bit flags in |style_bits|.
    // These constants correspond to CFS_* in Imm.h
    enum Style {
      DEFAULT = 0;          // CFS_DEFAULT
      RECT = 1;             // CFS_RECT
      POINT = 2;            // CFS_POINT
      FORCE_POSITION = 32;  // CFS_FORCE_POSITION
    }
    optional uint32 style_bits = 4 [default = 0];  // 0 means Style::DEFAULT
  }

  // An equivalent to CANDIDATEFORM in IMM32. (For Windows only)
  // TODO(yukawa): make a common candidate form format for all platforms.
  message CandidateForm {
    reserved 1;
    reserved "style";
    optional Point current_position = 2;
    optional Rectangle area = 3;
    // Used as bit flags in |style_bits|.
    // These constants correspond to CFS_* in Imm.h
    enum Style {
      DEFAULT = 0;        // CFS_DEFAULT
      CANDIDATEPOS = 64;  // CFS_CANDIDATEPOS
      EXCLUDE = 128;      // CFS_EXCLUDE
    }
    optional uint32 style_bits = 4 [default = 0];  // 0 means Style::DEFAULT
  }

  // An equivalent to IMECHARPOSITION in IMM32. (For Windows only)
  // TODO(yukawa): make a common candidate form format for all platforms.
  message CharacterPosition {
    optional uint32 position = 1;
    optional Point top_left = 2;
    optional uint32 line_height = 3;
    optional Rectangle document_area = 4;
  }

  // This message is a subset of Win32 GUITHREADINFO. (For Windows only)
  // TODO(yukawa): make a common candidate form format for all platforms.
  message CaretInfo {
    optional bool blinking = 1 [default = false];
    optional Rectangle caret_rect = 2;
    optional uint32 target_window_handle = 3;
  }

  // Visual information about mode indicator.
  message IndicatorInfo {
    optional Status status = 1;
  }

  // Application information Mozc UI is attaching
  message ApplicationInfo {
    optional uint32 process_id = 1;
    optional uint32 thread_id = 2;
    // used in Windows:
    // WHND of the message-only window:
    optional uint32 receiver_handle = 3;
    // used in Windows:
    // HWND of the window where composition is displayed.
    optional uint32 target_window_handle = 4;
    // used in Windows:
    // Preffered font for composition string.
    optional WinLogFont composition_font = 5;

    // Represents IM Framework used in the client.
    // Currently only Windows IM frameworks are supported.
    enum InputFrameworkType {
      UNKNOWN_FRAMEWORK = 0;  // Default. For backward compatibility.
      TSF = 1;
      IMM32 = 2;
      IMKit = 3;
      IBus = 4;
    }
    // Specifies which IM Framework is used in the client.
    optional InputFrameworkType input_framework = 6
        [default = UNKNOWN_FRAMEWORK];

    // used in Windows:
    // Specifies where and how the renderer process shows the composition
    // window (if necessary).
    optional CompositionForm composition_form = 7;

    // used in Windows:
    // Specifies where and how the renderer process shows the candidate
    // window (if necessary).
    // Currently only one candidate window is supported.
    // TODO(yukawa): support multiple candidate windows.
    optional CandidateForm candidate_form = 8;

    // used in Windows:
    // Indicates if a UI element is expected to be displayed or not.  Note
    // taht |RendererCommand::visible| should be prior to these flags, that is,
    // you should hide all UI elements if |RendererCommand::visible| is false
    // regardless of the visibility specified in this field.
    enum UIVisibility {
      ShowUIDefault = 0;
      ShowCompositionWindow = 1;
      ShowCandidateWindow = 2;
      ShowSuggestWindow = 4;
    }
    // used in Windows:
    optional int32 ui_visibilities = 9 [default = 0];  // ShowUIDefault

    // used in Windows:
    // Specifies the target position in composition window.
    optional CharacterPosition composition_target = 10;

    // used in Windows:
    // Represents caret information.
    optional CaretInfo caret_info = 11;

    reserved 12;
    reserved "message_sender_type";

    // A string representation of PangoFontDescription
    // http://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-description-from-string
    // This field is not application specific information but temporaly locate
    // here.
    // TODO(nona): Make new message if necessary.
    optional string pango_font_description = 13;

    // used in Windows:
    optional IndicatorInfo indicator_info = 14;
  }

  optional ApplicationInfo application_info = 5;
}
