<commit_before>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.gwt.client.ui.input.colorpicker;


import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

/**
 * Implements the SliderBar control.
 */
public final class CmsSliderBar extends HTML {

    /** Color mode for BLUE. */
    public static final int BLUE = 6;
    /** Color mode for BRIGHTNESS. */
    public static final int BRIGHTNESS = 2;
    /** Layer to affect. */
    public static final int COLORBAR_A = 1;
    /** Layer to affect. */
    public static final int COLORBAR_B = 2;
    /** Layer to affect. */
    public static final int COLORBAR_C = 3;
    /** Layer to affect. */
    public static final int COLORBAR_D = 4;
    /** Color mode for GREEN. */
    public static final int GREEN = 5;
    /** Color mode for HUE. */
    public static final int HUE = 3;
    /** Color mode for RED. */
    public static final int RED = 4;
    /** Color mode for SATURATIN. */
    public static final int SATURATIN = 1;

    /** Value if the mouse should be captured or not. */
    private boolean m_capturedMouse;
    /** Image holder. */
    private Image m_colorA;
    /** Image holder. */
    private Image m_colorB;
    /** Image holder. */
    private Image m_colorC;
    /** Image holder. */
    private Image m_colorD;

    /** Image resourcen. */
    private I_CmsColorPickerImageResource m_cpImageBundle;
    /** The parent CmsColorPicker. */
    private CmsColorSelector m_parent;
    /** Image holder. */
    private Image m_slider;

    /***
     * Initialize the SliderMap.<p>
     * @param parent the parent of the slider bar
     */
    public CmsSliderBar(CmsColorSelector parent) {

        super();

        m_parent = parent;

        setWidth("40px");
        setHeight("256px");

        m_cpImageBundle = (I_CmsColorPickerImageResource)GWT.create(I_CmsColorPickerImageResource.class);

        m_colorA = new Image(m_cpImageBundle.bar_white());
        m_colorB = new Image(m_cpImageBundle.bar_white());
        m_colorC = new Image(m_cpImageBundle.bar_white());
        m_colorD = new Image(m_cpImageBundle.bar_saturation());
        m_slider = new Image(m_cpImageBundle.rangearrows());

        getElement().appendChild(m_colorA.getElement());
        getElement().appendChild(m_colorB.getElement());
        getElement().appendChild(m_colorC.getElement());
        getElement().appendChild(m_colorD.getElement());
        getElement().appendChild(m_slider.getElement());

        m_colorA.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorA.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorA.getElement().getStyle().setBorderColor("black");
        m_colorB.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorB.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorB.getElement().getStyle().setBorderColor("black");
        m_colorC.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorC.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorC.getElement().getStyle().setBorderColor("black");
        m_colorD.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorD.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorD.getElement().getStyle().setBorderColor("black");

    }

    /**
     * @see com.google.gwt.user.client.ui.Widget#onAttach()
     */
    @Override
    public void onAttach() {

        super.onAttach();

        m_colorA.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorA.getElement().getStyle().setLeft(10, Unit.PX);

        m_colorB.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorB.getElement().getStyle().setLeft(10, Unit.PX);
        m_colorB.getElement().getStyle().setTop(-260, Unit.PX);

        m_colorC.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorC.getElement().getStyle().setLeft(10, Unit.PX);
        m_colorC.getElement().getStyle().setTop(-520, Unit.PX);

        m_colorD.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorD.getElement().getStyle().setLeft(10, Unit.PX);
        m_colorD.getElement().getStyle().setTop(-780, Unit.PX);

        m_slider.getElement().getStyle().setPosition(Position.RELATIVE);
        m_slider.getElement().getStyle().setLeft(1, Unit.PX);
        m_slider.getElement().getStyle().setTop(-1047, Unit.PX);
    }

    /**
     * Fired whenever a browser event is received.<p>
     * @param event Event to process
     */
    @Override
    public void onBrowserEvent(Event event) {

        switch (DOM.eventGetType(event)) {
            case Event.ONMOUSEUP:
                Event.releaseCapture(getElement());
                m_capturedMouse = false;
                break;
            case Event.ONMOUSEDOWN:
                Event.setCapture(getElement());
                m_capturedMouse = true;
                //$FALL-THROUGH$
            case Event.ONMOUSEMOVE:
                if (m_capturedMouse) {
                    DOM.eventPreventDefault(event);

                    int y = (event.getClientY() - getAbsoluteTop()) + Window.getScrollTop();
                    setSliderPosition(y);
                    if (m_parent != null) {
                        m_parent.onBarSelected(y);
                    }
                }
                //$FALL-THROUGH$
            default:

        }
    }
<commit_msg>Correct issue by moving the slider bar and get the correct value to generate the color. Correct for Chrome.<commit_after>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.gwt.client.ui.input.colorpicker;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

/**
 * Implements the SliderBar control.
 */
public final class CmsSliderBar extends HTML {

    /** Color mode for BLUE. */
    public static final int BLUE = 6;
    /** Color mode for BRIGHTNESS. */
    public static final int BRIGHTNESS = 2;
    /** Layer to affect. */
    public static final int COLORBAR_A = 1;
    /** Layer to affect. */
    public static final int COLORBAR_B = 2;
    /** Layer to affect. */
    public static final int COLORBAR_C = 3;
    /** Layer to affect. */
    public static final int COLORBAR_D = 4;
    /** Color mode for GREEN. */
    public static final int GREEN = 5;
    /** Color mode for HUE. */
    public static final int HUE = 3;
    /** Color mode for RED. */
    public static final int RED = 4;
    /** Color mode for SATURATIN. */
    public static final int SATURATIN = 1;

    /** Value if the mouse should be captured or not. */
    private boolean m_capturedMouse;
    /** Image holder. */
    private Image m_colorA;
    /** Image holder. */
    private Image m_colorB;
    /** Image holder. */
    private Image m_colorC;
    /** Image holder. */
    private Image m_colorD;

    /** Image resourcen. */
    private I_CmsColorPickerImageResource m_cpImageBundle;
    /** The parent CmsColorPicker. */
    private CmsColorSelector m_parent;
    /** Image holder. */
    private Image m_slider;

    /***
     * Initialize the SliderMap.<p>
     * @param parent the parent of the slider bar
     */
    public CmsSliderBar(CmsColorSelector parent) {

        super();

        m_parent = parent;

        setWidth("40px");
        setHeight("256px");

        m_cpImageBundle = (I_CmsColorPickerImageResource)GWT.create(I_CmsColorPickerImageResource.class);

        m_colorA = new Image(m_cpImageBundle.bar_white());
        m_colorB = new Image(m_cpImageBundle.bar_white());
        m_colorC = new Image(m_cpImageBundle.bar_white());
        m_colorD = new Image(m_cpImageBundle.bar_saturation());
        m_slider = new Image(m_cpImageBundle.rangearrows());

        getElement().appendChild(m_colorA.getElement());
        getElement().appendChild(m_colorB.getElement());
        getElement().appendChild(m_colorC.getElement());
        getElement().appendChild(m_colorD.getElement());
        getElement().appendChild(m_slider.getElement());

        m_colorA.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorA.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorA.getElement().getStyle().setBorderColor("black");
        m_colorB.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorB.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorB.getElement().getStyle().setBorderColor("black");
        m_colorC.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorC.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorC.getElement().getStyle().setBorderColor("black");
        m_colorD.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        m_colorD.getElement().getStyle().setBorderWidth(1, Unit.PX);
        m_colorD.getElement().getStyle().setBorderColor("black");

    }

    /**
     * @see com.google.gwt.user.client.ui.Widget#onAttach()
     */
    @Override
    public void onAttach() {

        super.onAttach();

        m_colorA.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorA.getElement().getStyle().setLeft(10, Unit.PX);

        m_colorB.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorB.getElement().getStyle().setLeft(10, Unit.PX);
        m_colorB.getElement().getStyle().setTop(-260, Unit.PX);

        m_colorC.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorC.getElement().getStyle().setLeft(10, Unit.PX);
        m_colorC.getElement().getStyle().setTop(-520, Unit.PX);

        m_colorD.getElement().getStyle().setPosition(Position.RELATIVE);
        m_colorD.getElement().getStyle().setLeft(10, Unit.PX);
        m_colorD.getElement().getStyle().setTop(-780, Unit.PX);

        m_slider.getElement().getStyle().setPosition(Position.RELATIVE);
        m_slider.getElement().getStyle().setLeft(1, Unit.PX);
        m_slider.getElement().getStyle().setTop(-1047, Unit.PX);
    }

    /**
     * Fired whenever a browser event is received.<p>
     * @param event Event to process
     */
    @Override
    public void onBrowserEvent(Event event) {

        switch (DOM.eventGetType(event)) {
            case Event.ONMOUSEUP:
                Event.releaseCapture(getElement());
                m_capturedMouse = false;
                break;
            case Event.ONMOUSEDOWN:
                Event.setCapture(getElement());
                m_capturedMouse = true;
                //$FALL-THROUGH$
            case Event.ONMOUSEMOVE:
                if (m_capturedMouse) {
                    DOM.eventPreventDefault(event);
                    double abolut_top = getAbsoluteTop();
                    int y = ((event.getClientY() - (int)abolut_top) + Window.getScrollTop());
                    setSliderPosition(y);
                    if (m_parent != null) {
                        m_parent.onBarSelected(y);
                    }
                }
                //$FALL-THROUGH$
            default:

        }
    }

{'fraction_non_alphanumeric': 0.12091950709807596, 'fraction_numerical': 0.008215032067449737, 'mean_word_length': 2.7538544766026507, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6273197', 'n_tokens_mistral': 4226, 'n_tokens_neox': 4021, 'n_words': 959}