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 UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/weak_ptr.h" 11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/time/time.h" 124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/base/models/combobox_model_observer.h" 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/gfx/animation/animation_delegate.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h" 15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/views/controls/button/button.h" 16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/views/controls/menu/menu_delegate.h" 17fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch#include "ui/views/controls/prefix_delegate.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class FontList; 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class SlideAnimation; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComboboxModel; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComboboxListener; 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class ComboboxMenuRunner; 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class CustomButton; 33d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class FocusableBorder; 34d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class MenuRunner; 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class MenuRunnerHandler; 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class Painter; 37fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdochclass PrefixSelector; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 39d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// A non-editable combobox (aka a drop-down list or selector). 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Combobox has two distinct parts, the drop down arrow and the text. Combobox 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// offers two distinct behaviors: 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// * STYLE_NORMAL: typical combobox, clicking on the text and/or button shows 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the drop down, arrow keys change selection, selected index can be changed by 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the user to something other than the first item. 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// * STYLE_ACTION: clicking on the text notifies the listener. The menu can be 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// shown only by clicking on the arrow. The selected index is always reverted to 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 0 after the listener is notified. 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class VIEWS_EXPORT Combobox : public MenuDelegate, 49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public PrefixDelegate, 50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public ui::ComboboxModelObserver, 51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public ButtonListener { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The style of the combobox. 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) enum Style { 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) STYLE_NORMAL, 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) STYLE_ACTION, 57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The combobox's class name. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const char kViewClassName[]; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |model| is not owned by the combobox. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Combobox(ui::ComboboxModel* model); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Combobox(); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const gfx::FontList& GetFontList(); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the listener which will be called when a selection has been made. 69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void set_listener(ComboboxListener* listener) { listener_ = listener; } 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetStyle(Style style); 72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Informs the combobox that its model changed. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ModelChanged(); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/Sets the selected index. 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selected_index() const { return selected_index_; } 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetSelectedIndex(int index); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Looks for the first occurrence of |value| in |model()|. If found, selects 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the found index and returns true. Otherwise simply noops and returns false. 82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool SelectValue(const base::string16& value); 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::ComboboxModel* model() const { return model_; } 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the accessible name of the combobox. 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetAccessibleName(const base::string16& name); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Visually marks the combobox as having an invalid value selected. 90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // When invalid, it paints with white text on a red background. 91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Callers are responsible for restoring validity with selection changes. 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetInvalid(bool invalid); 93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool invalid() const { return invalid_; } 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from View: 96cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE; 97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual const char* GetClassName() const OVERRIDE; 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE; 101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnFocus() OVERRIDE; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnBlur() OVERRIDE; 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 105fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; 106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void Layout() OVERRIDE; 107fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch 108d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Overridden from MenuDelegate: 109d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual bool IsItemChecked(int id) const OVERRIDE; 110d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual bool IsCommandEnabled(int id) const OVERRIDE; 111d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void ExecuteCommand(int id) OVERRIDE; 112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual bool GetAccelerator(int id, 113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::Accelerator* accelerator) const OVERRIDE; 114d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 115fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch // Overridden from PrefixDelegate: 116fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch virtual int GetRowCount() OVERRIDE; 117fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch virtual int GetSelectedRow() OVERRIDE; 118fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch virtual void SetSelectedRow(int row) OVERRIDE; 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual base::string16 GetTextForRow(int row) OVERRIDE; 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Overriden from ComboboxModelObserver: 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnComboboxModelChanged(ui::ComboboxModel* model) OVERRIDE; 1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Overriden from ButtonListener: 125a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE; 126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 127d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private: 128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(ComboboxTest, Click); 129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(ComboboxTest, ClickButDisabled); 130a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(ComboboxTest, NotifyOnClickWithMouse); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(ComboboxTest, ContentWidth); 132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 133d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Updates the combobox's content from its model. 134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void UpdateFromModel(); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Updates the border according to the current state. 137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void UpdateBorder(); 138a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Given bounds within our View, this helper mirrors the bounds if necessary. 140d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void AdjustBoundsForRTLUI(gfx::Rect* rect) const; 141d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Draws the selected value of the drop down list 143d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void PaintText(gfx::Canvas* canvas); 144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 145a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Draws the button images. 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void PaintButtons(gfx::Canvas* canvas); 147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 148d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Show the drop down list 149d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void ShowDropDownMenu(ui::MenuSourceType source_type); 150d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 151d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Called when the selection is changed by the user. 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnPerformAction(); 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void NotifyPerformAction(); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AfterPerformAction(); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Converts a menu command ID to a menu item index. 1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int MenuCommandToIndex(int menu_command_id) const; 1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 159a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int GetDisclosureArrowLeftPadding() const; 160a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int GetDisclosureArrowRightPadding() const; 161a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Returns the size of the disclosure arrow. 1636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) gfx::Size ArrowSize() const; 1646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 165a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Handles the clicking event. 166a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void HandleClickEvent(); 167a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Our model. Not owned. 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::ComboboxModel* model_; 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The visual style of this combobox. 172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Style style_; 173a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Our listener. Not owned. Notified when the selected index change. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ComboboxListener* listener_; 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 177d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The current selected index; -1 and means no selection. 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selected_index_; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // True when the selection is visually denoted as invalid. 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool invalid_; 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The accessible name of this combobox. 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 accessible_name_; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 186d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // A helper used to select entries by keyboard input. 187fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch scoped_ptr<PrefixSelector> selector_; 188fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch 189d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Responsible for showing the context menu. 190d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scoped_ptr<MenuRunner> dropdown_list_menu_runner_; 191d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 192d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Is the drop down list showing 193d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool dropdown_open_; 194d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 195d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Like MenuButton, we use a time object in order to keep track of when the 196d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // combobox was closed. The time is used for simulating menu behavior; that 197d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // is, if the menu is shown and the button is pressed, we need to close the 198d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // menu. There is no clean way to get the second click event because the 199d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // menu is displayed using a modal loop and, unlike regular menus in Windows, 200d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // the button is not part of the displayed menu. 201d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::Time closed_time_; 202d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 203d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The maximum dimensions of the content in the dropdown 204cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) mutable gfx::Size content_size_; 205d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The painters or images that are used when |style_| is STYLE_BUTTONS. The 207a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // first index means the state of unfocused or focused. 208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The images are owned by ResourceBundle. 209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<Painter> body_button_painters_[2][Button::STATE_COUNT]; 210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::vector<const gfx::ImageSkia*> 211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) menu_button_images_[2][Button::STATE_COUNT]; 212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The transparent buttons to handle events and render buttons. These are 214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // placed on top of this combobox as child views, accept event and manage the 215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // button states. These are not rendered but when |style_| is 216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to 217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // these button states. 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The base View takes the ownerships of these as child views. 219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CustomButton* text_button_; 220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CustomButton* arrow_button_; 221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Used for making calbacks. 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::WeakPtrFactory<Combobox> weak_ptr_factory_; 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(Combobox); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ 231