Home | History | Annotate | Download | only in ash
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ASH_POPUP_MESSAGE_H_
      6 #define ASH_POPUP_MESSAGE_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "base/basictypes.h"
     10 #include "base/strings/string16.h"
     11 #include "ui/gfx/rect.h"
     12 #include "ui/views/bubble/bubble_border.h"
     13 
     14 namespace views {
     15 class BubbleDelegateView;
     16 class Widget;
     17 }
     18 
     19 namespace ash {
     20 
     21 // PopupMessage shows a message to the user. Since the user is not able to
     22 // dismiss it, the calling code needs to explictly close and destroy it.
     23 class ASH_EXPORT PopupMessage {
     24  public:
     25   enum IconType {
     26     ICON_WARNING,
     27     ICON_NONE
     28   };
     29 
     30   // Creates a message pointing towards |anchor| with the requested
     31   // |arrow_orientation|. The message contains an optional |caption| which is
     32   // drawn in bold and an optional |message| together with an optional icon of
     33   // shape |message_type|. If a component in |size_override| is not 0 the value
     34   // is the used as output size. If |arrow_offset| is not 0, the number is the
     35   // arrow offset in pixels from the border.
     36   //
     37   // Here is the layout (arrow given as TOP_LEFT):
     38   //                    |--------|
     39   //                    | Anchor |
     40   //                    |--------|
     41   //       |-arrow_offset---^
     42   //       +-------------------------------------------------+
     43   //      -|                                                 |-
     44   //  icon |  [!]  Caption in bold which can be multi line   | caption_label
     45   //      -|                                                 |-
     46   //       |       Message text which can be multi line      | message_label
     47   //       |       as well.                                  |
     48   //       |                                                 |-
     49   //       +-------------------------------------------------+
     50   PopupMessage(const base::string16& caption,
     51                const base::string16& message,
     52                IconType message_type,
     53                views::View* anchor,
     54                views::BubbleBorder::Arrow arrow,
     55                const gfx::Size& size_override,
     56                int arrow_offset);
     57   // If the message was not explicitly closed before, it closes the message
     58   // without animation.
     59   virtual ~PopupMessage();
     60 
     61   // Closes the message with a fade out animation.
     62   void Close();
     63 
     64  private:
     65   class MessageBubble;
     66 
     67   void CancelHidingAnimation();
     68 
     69   MessageBubble* view_;
     70   views::Widget* widget_;
     71 
     72   // Variables of the construction time.
     73   views::View* anchor_;
     74   base::string16 caption_;
     75   base::string16 message_;
     76   IconType message_type_;
     77   views::BubbleBorder::Arrow arrow_orientation_;
     78 
     79   DISALLOW_COPY_AND_ASSIGN(PopupMessage);
     80 };
     81 
     82 }  // namespace ash
     83 
     84 #endif  // ASH_POPUP_MESSAGE_H_
     85