intl/lwbrk/LineBreaker.h
author Masayuki Nakano <masayuki@d-toybox.com>
Mon, 26 Mar 2018 23:56:53 +0900
changeset 463914 222afb91d7d3e0338965dea63536dd28f5348811
parent 448116 80ed22b2c35c71738d8bb17e5ab9923753a4afcb
child 505383 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Bug 1448876 - Get rid of nsIClipboardDragDropHooks and nsIClipboardDragDropHookList interfaces r=bz nsIClipboardDragDropHooks and nsIClipboardDragDropHookList allow XUL apps to customize drag and drop operation and paste operation. However, this feature was used only by ChatZilla and it doesn't work on Gecko anymore. So, we can get rid of them from our tree. MozReview-Commit-ID: Ibs3V1gI8Ry

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_intl_LineBreaker_h__
#define mozilla_intl_LineBreaker_h__

#include "nscore.h"
#include "nsISupports.h"

#define NS_LINEBREAKER_NEED_MORE_TEXT -1

namespace mozilla {
namespace intl {

class LineBreaker
{
public:
  NS_INLINE_DECL_REFCOUNTING(LineBreaker)

  enum {
    kWordBreak_Normal   = 0, // default
    kWordBreak_BreakAll = 1, // break all
    kWordBreak_KeepAll  = 2  // always keep
  };

  static already_AddRefed<LineBreaker> Create();

  int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);

  int32_t Prev( const char16_t* aText, uint32_t aLen, uint32_t aPos);

  // Call this on a word with whitespace at either end. We will apply JISx4051
  // rules to find breaks inside the word. aBreakBefore is set to the break-
  // before status of each character; aBreakBefore[0] will always be false
  // because we never return a break before the first character.
  // aLength is the length of the aText array and also the length of the aBreakBefore
  // output array.
  void GetJISx4051Breaks(const char16_t* aText, uint32_t aLength,
                         uint8_t aWordBreak,
                         uint8_t* aBreakBefore);
  void GetJISx4051Breaks(const uint8_t* aText, uint32_t aLength,
                         uint8_t aWordBreak,
                         uint8_t* aBreakBefore);

private:
  ~LineBreaker() { }

  int32_t WordMove(const char16_t* aText, uint32_t aLen, uint32_t aPos,
                   int8_t aDirection);
};

static inline bool
NS_IsSpace(char16_t u)
{
  return u == 0x0020 ||                  // SPACE
         u == 0x0009 ||                  // CHARACTER TABULATION
         u == 0x000D ||                  // CARRIAGE RETURN
         (0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE,
                                         // EM SPACE, THREE-PER-EM SPACE,
                                         // FOUR-PER-SPACE, SIX-PER-EM SPACE,
         (0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE,
                                         // HAIR SPACE, ZERO WIDTH SPACE
         u == 0x1361 ||                  // ETHIOPIC WORDSPACE
         u == 0x1680 ||                  // OGHAM SPACE MARK
         u == 0x205F;                    // MEDIUM MATHEMATICAL SPACE
}

static inline bool
NS_NeedsPlatformNativeHandling(char16_t aChar)
{
  return (0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan
         (0x1780 <= aChar && aChar <= 0x17ff);   // Khmer
}

} // namespace intl
} // namespace mozilla

#endif  /* mozilla_intl_LineBreaker_h__ */