1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // TODO(nona): Implement delay rendering.
31 
32 #ifndef MOZC_RENDERER_UNIX_INFOLIST_WINDOW_H_
33 #define MOZC_RENDERER_UNIX_INFOLIST_WINDOW_H_
34 
35 #include <gtk/gtk.h>
36 
37 #include <memory>
38 
39 #include "base/coordinates.h"
40 #include "protocol/renderer_command.pb.h"
41 #include "protocol/renderer_style.pb.h"
42 #include "renderer/unix/cairo_factory_interface.h"
43 #include "renderer/unix/draw_tool_interface.h"
44 #include "renderer/unix/gtk_window_base.h"
45 #include "renderer/unix/text_renderer_interface.h"
46 #include "testing/base/public/gunit_prod.h"
47 
48 namespace mozc {
49 namespace renderer {
50 namespace gtk {
51 
52 class InfolistWindow : public GtkWindowBase {
53  public:
54   // GtkWindowBase(InfolistWindow) has ownership of GtkWrapperInterface *gtk;
55   explicit InfolistWindow(
56       TextRendererInterface *text_renderer,
57       DrawToolInterface *draw_tool,
58       GtkWrapperInterface *gtk,
59       CairoFactoryInterface *cairo_factory);
~InfolistWindow()60   virtual ~InfolistWindow() {}
61 
62   virtual Size Update(const commands::Candidates &candidates);
63   virtual void Initialize();
64   // This function is not used in infolist window.
65   virtual Rect GetCandidateColumnInClientCord() const;
66   virtual void ReloadFontConfig(const string &font_description);
67 
68  protected:
69   virtual bool OnPaint(GtkWidget *widget, GdkEventExpose *event);
70 
71  private:
72   struct RenderingRowRects {
73     Rect title_rect;
74     Rect title_back_rect;
75     Rect desc_rect;
76     Rect desc_back_rect;
77     Rect whole_rect;
78   };
79 
80   void Draw();
81 
82   // Draws specified description row and returns it's height.
83   int DrawRow(int row, int ypos);
84 
85   // Gets target rendering rects.
86   RenderingRowRects GetRowRects(int row, int ypos);
87 
88   // Draws caption string and returns it's height.
89   int DrawCaption();
90 
91   // Draws infolist window frame line.
92   void DrawFrame(int height);
93 
94   // Calculate background and text displaying area based on style, text font and
95   // top position.
96   void GetRenderingRects(const renderer::RendererStyle::TextStyle &style,
97                          const string &text,
98                          FontSpecInterface::FONT_TYPE font_type,
99                          int top,
100                          Rect *background_rect,
101                          Rect *textarea_rect);
102 
103   friend class InfolistWindowTest;
104   FRIEND_TEST(InfolistWindowTest, DrawFrameTest);
105   FRIEND_TEST(InfolistWindowTest, DrawRowTest);
106   FRIEND_TEST(InfolistWindowTest, GetRowRectsTest);
107   FRIEND_TEST(InfolistWindowTest, DrawCaptionTest);
108   FRIEND_TEST(InfolistWindowTest, GetRenderingRectsTest);
109 
110   commands::Candidates candidates_;
111   std::unique_ptr<TextRendererInterface> text_renderer_;
112   std::unique_ptr<RendererStyle> style_;
113   std::unique_ptr<DrawToolInterface> draw_tool_;
114   std::unique_ptr<CairoFactoryInterface> cairo_factory_;
115   DISALLOW_COPY_AND_ASSIGN(InfolistWindow);
116 };
117 
118 }  // namespace gtk
119 }  // namespace renderer
120 }  // namespace mozc
121 #endif  // MOZC_RENDERER_UNIX_INFOLIST_WINDOW_H_
122