| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/ime/ime_window_frame_view.h" | 5 #include "chrome/browser/ui/views/ime/ime_window_frame_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/ime/ime_window_view.h" | 7 #include "chrome/browser/ui/views/ime/ime_window_view.h" |
| 8 #include "chrome/grit/browser_resources.h" | 8 #include "chrome/grit/browser_resources.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/views/resources/grit/views_resources.h" | 21 #include "ui/views/resources/grit/views_resources.h" |
| 22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 23 #include "ui/views/widget/widget_delegate.h" | 23 #include "ui/views/widget/widget_delegate.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // The distance values for layout in DIPs. | 27 // The distance values for layout in DIPs. |
| 28 const int kButtonSize = 24; | 28 const int kButtonSize = 24; |
| 29 const int kBorderThickness = 1; | 29 const int kBorderThickness = 1; |
| 30 const int kIconSize = 16; | 30 const int kIconSize = 16; |
| 31 const int kTitleAndButtonPadding = 11; | |
| 32 const int kTitlebarHeight = 32; | 31 const int kTitlebarHeight = 32; |
| 33 const int kTitlebarLeftPadding = 8; | 32 const int kTitlebarLeftPadding = 8; |
| 34 const int kTitlebarRightPadding = 6; | 33 const int kTitlebarRightPadding = 6; |
| 35 | 34 |
| 36 // Colors used to draw border, titlebar background and title text. | 35 // Colors used to draw border, titlebar background and title text. |
| 37 const SkColor kBackgroundColor = SkColorSetRGB(0xec, 0xef, 0xf1); | 36 const SkColor kBackgroundColor = SkColorSetRGB(0xec, 0xef, 0xf1); |
| 38 const SkColor kBorderColor = SkColorSetRGB(0xda, 0xdf, 0xe1); | 37 const SkColor kBorderColor = SkColorSetRGB(0xda, 0xdf, 0xe1); |
| 39 const SkColor kTitleTextColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | |
| 40 | 38 |
| 41 } // namespace | 39 } // namespace |
| 42 | 40 |
| 43 namespace ui { | 41 namespace ui { |
| 44 | 42 |
| 45 ImeWindowFrameView::ImeWindowFrameView(ImeWindowView* ime_window_view, | 43 ImeWindowFrameView::ImeWindowFrameView(ImeWindowView* ime_window_view, |
| 46 ImeWindow::Mode mode) | 44 ImeWindow::Mode mode) |
| 47 : ime_window_view_(ime_window_view), | 45 : ime_window_view_(ime_window_view), |
| 48 mode_(mode), | 46 mode_(mode), |
| 49 close_button_(nullptr), | 47 close_button_(nullptr), |
| 50 title_icon_(nullptr), | 48 title_icon_(nullptr) {} |
| 51 title_label_(nullptr) {} | |
| 52 | 49 |
| 53 ImeWindowFrameView::~ImeWindowFrameView() {} | 50 ImeWindowFrameView::~ImeWindowFrameView() {} |
| 54 | 51 |
| 55 void ImeWindowFrameView::Init() { | 52 void ImeWindowFrameView::Init() { |
| 56 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 57 | 54 |
| 58 close_button_ = new views::ImageButton(this); | 55 close_button_ = new views::ImageButton(this); |
| 59 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 56 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| 60 rb.GetImageSkiaNamed(IDR_IME_WINDOW_CLOSE)); | 57 rb.GetImageSkiaNamed(IDR_IME_WINDOW_CLOSE)); |
| 61 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 58 close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
| 62 rb.GetImageSkiaNamed(IDR_IME_WINDOW_CLOSE_H)); | 59 rb.GetImageSkiaNamed(IDR_IME_WINDOW_CLOSE_H)); |
| 63 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 60 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
| 64 rb.GetImageSkiaNamed(IDR_IME_WINDOW_CLOSE_C)); | 61 rb.GetImageSkiaNamed(IDR_IME_WINDOW_CLOSE_C)); |
| 65 close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 62 close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 66 views::ImageButton::ALIGN_MIDDLE); | 63 views::ImageButton::ALIGN_MIDDLE); |
| 67 AddChildView(close_button_); | 64 AddChildView(close_button_); |
| 68 | 65 |
| 69 title_icon_ = new views::ImageView(); | 66 title_icon_ = new views::ImageView(); |
| 70 title_icon_->SetImage(ime_window_view_->GetWindowIcon()); | 67 title_icon_->SetImage(ime_window_view_->GetWindowIcon()); |
| 71 title_icon_->SetTooltipText(ime_window_view_->GetWindowTitle()); | 68 title_icon_->SetTooltipText(ime_window_view_->GetWindowTitle()); |
| 72 AddChildView(title_icon_); | 69 AddChildView(title_icon_); |
| 73 | |
| 74 title_label_ = new views::Label(ime_window_view_->GetWindowTitle(), | |
| 75 rb.GetFontList(ui::ResourceBundle::BoldFont)); | |
| 76 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 77 title_label_->SetAutoColorReadabilityEnabled(false); | |
| 78 AddChildView(title_label_); | |
| 79 } | |
| 80 | |
| 81 void ImeWindowFrameView::UpdateTitle() { | |
| 82 UpdateWindowTitle(); | |
| 83 } | 70 } |
| 84 | 71 |
| 85 void ImeWindowFrameView::UpdateIcon() { | 72 void ImeWindowFrameView::UpdateIcon() { |
| 86 UpdateWindowIcon(); | 73 UpdateWindowIcon(); |
| 87 } | 74 } |
| 88 | 75 |
| 89 gfx::Rect ImeWindowFrameView::GetBoundsForClientView() const { | 76 gfx::Rect ImeWindowFrameView::GetBoundsForClientView() const { |
| 90 if (in_follow_cursor_mode()) { | 77 if (in_follow_cursor_mode()) { |
| 91 return gfx::Rect(kTitlebarHeight, kBorderThickness, | 78 return gfx::Rect(kTitlebarHeight, kBorderThickness, |
| 92 std::max(0, width() - kTitlebarHeight - kBorderThickness), | 79 std::max(0, width() - kTitlebarHeight - kBorderThickness), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 125 |
| 139 window_mask->close(); | 126 window_mask->close(); |
| 140 } | 127 } |
| 141 | 128 |
| 142 void ImeWindowFrameView::ResetWindowControls() {} | 129 void ImeWindowFrameView::ResetWindowControls() {} |
| 143 | 130 |
| 144 void ImeWindowFrameView::UpdateWindowIcon() { | 131 void ImeWindowFrameView::UpdateWindowIcon() { |
| 145 title_icon_->SchedulePaint(); | 132 title_icon_->SchedulePaint(); |
| 146 } | 133 } |
| 147 | 134 |
| 148 void ImeWindowFrameView::UpdateWindowTitle() { | 135 void ImeWindowFrameView::UpdateWindowTitle() {} |
| 149 title_label_->SetText(ime_window_view_->GetWindowTitle()); | |
| 150 } | |
| 151 | 136 |
| 152 void ImeWindowFrameView::SizeConstraintsChanged() {} | 137 void ImeWindowFrameView::SizeConstraintsChanged() {} |
| 153 | 138 |
| 154 gfx::Size ImeWindowFrameView::GetPreferredSize() const { | 139 gfx::Size ImeWindowFrameView::GetPreferredSize() const { |
| 155 gfx::Size pref_size = | 140 gfx::Size pref_size = |
| 156 ime_window_view_->window()->client_view()->GetPreferredSize(); | 141 ime_window_view_->window()->client_view()->GetPreferredSize(); |
| 157 gfx::Rect bounds(0, 0, pref_size.width(), pref_size.height()); | 142 gfx::Rect bounds(0, 0, pref_size.width(), pref_size.height()); |
| 158 return ime_window_view_->window() | 143 return ime_window_view_->window() |
| 159 ->non_client_view() | 144 ->non_client_view() |
| 160 ->GetWindowBoundsForClientBounds(bounds) | 145 ->GetWindowBoundsForClientBounds(bounds) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 173 // Layout the icon. | 158 // Layout the icon. |
| 174 // TODO(shuchen): Consider the RTL case. | 159 // TODO(shuchen): Consider the RTL case. |
| 175 int icon_y = (kTitlebarHeight - kIconSize) / 2; | 160 int icon_y = (kTitlebarHeight - kIconSize) / 2; |
| 176 bool follow_cursor = in_follow_cursor_mode(); | 161 bool follow_cursor = in_follow_cursor_mode(); |
| 177 title_icon_->SetBounds(follow_cursor ? icon_y : kTitlebarLeftPadding, | 162 title_icon_->SetBounds(follow_cursor ? icon_y : kTitlebarLeftPadding, |
| 178 follow_cursor ? kTitlebarLeftPadding : icon_y, | 163 follow_cursor ? kTitlebarLeftPadding : icon_y, |
| 179 kIconSize, kIconSize); | 164 kIconSize, kIconSize); |
| 180 | 165 |
| 181 if (follow_cursor) { | 166 if (follow_cursor) { |
| 182 close_button_->SetVisible(false); | 167 close_button_->SetVisible(false); |
| 183 title_label_->SetVisible(false); | |
| 184 } else { | 168 } else { |
| 185 // Layout the close button. | 169 // Layout the close button. |
| 186 int right = width(); | |
| 187 close_button_->SetBounds(width() - kTitlebarRightPadding - kButtonSize, | 170 close_button_->SetBounds(width() - kTitlebarRightPadding - kButtonSize, |
| 188 (kTitlebarHeight - kButtonSize) / 2, kButtonSize, | 171 (kTitlebarHeight - kButtonSize) / 2, kButtonSize, |
| 189 kButtonSize); | 172 kButtonSize); |
| 190 right = close_button_->x(); | |
| 191 | |
| 192 // Layout the title. | |
| 193 int title_x = title_icon_->bounds().right() + kTitleAndButtonPadding; | |
| 194 int title_height = title_label_->font_list().GetHeight(); | |
| 195 title_label_->SetBounds( | |
| 196 title_x, icon_y + ((kIconSize - title_height - 1) / 2), | |
| 197 std::max(0, right - kTitleAndButtonPadding - title_x), title_height); | |
| 198 } | 173 } |
| 199 } | 174 } |
| 200 | 175 |
| 201 void ImeWindowFrameView::OnPaint(gfx::Canvas* canvas) { | 176 void ImeWindowFrameView::OnPaint(gfx::Canvas* canvas) { |
| 202 UpdateControlStyles(); | |
| 203 PaintFrameBackground(canvas); | 177 PaintFrameBackground(canvas); |
| 204 } | 178 } |
| 205 | 179 |
| 206 bool ImeWindowFrameView::OnMousePressed(const ui::MouseEvent& event) { | 180 bool ImeWindowFrameView::OnMousePressed(const ui::MouseEvent& event) { |
| 207 if (event.IsOnlyLeftMouseButton()) { | 181 if (event.IsOnlyLeftMouseButton()) { |
| 208 gfx::Point mouse_location = event.location(); | 182 gfx::Point mouse_location = event.location(); |
| 209 views::View::ConvertPointToScreen(this, &mouse_location); | 183 views::View::ConvertPointToScreen(this, &mouse_location); |
| 210 return ime_window_view_->OnTitlebarPointerPressed( | 184 return ime_window_view_->OnTitlebarPointerPressed( |
| 211 mouse_location, ImeWindowView::PointerType::MOUSE); | 185 mouse_location, ImeWindowView::PointerType::MOUSE); |
| 212 } | 186 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if (handled) | 234 if (handled) |
| 261 event->SetHandled(); | 235 event->SetHandled(); |
| 262 } | 236 } |
| 263 | 237 |
| 264 void ImeWindowFrameView::ButtonPressed(views::Button* sender, | 238 void ImeWindowFrameView::ButtonPressed(views::Button* sender, |
| 265 const ui::Event& event) { | 239 const ui::Event& event) { |
| 266 if (sender == close_button_) | 240 if (sender == close_button_) |
| 267 ime_window_view_->Close(); | 241 ime_window_view_->Close(); |
| 268 } | 242 } |
| 269 | 243 |
| 270 void ImeWindowFrameView::UpdateControlStyles() { | |
| 271 title_label_->SetEnabledColor(kTitleTextColor); | |
| 272 } | |
| 273 | |
| 274 void ImeWindowFrameView::PaintFrameBackground(gfx::Canvas* canvas) { | 244 void ImeWindowFrameView::PaintFrameBackground(gfx::Canvas* canvas) { |
| 275 canvas->DrawColor(kBackgroundColor); | 245 canvas->DrawColor(kBackgroundColor); |
| 276 | 246 |
| 277 // left border. | 247 // left border. |
| 278 canvas->FillRect(gfx::Rect(0, 0, kBorderThickness, height()), | 248 canvas->FillRect(gfx::Rect(0, 0, kBorderThickness, height()), |
| 279 kBorderColor); | 249 kBorderColor); |
| 280 // top border. | 250 // top border. |
| 281 canvas->FillRect(gfx::Rect(0, 0, width(), kBorderThickness), | 251 canvas->FillRect(gfx::Rect(0, 0, width(), kBorderThickness), |
| 282 kBorderColor); | 252 kBorderColor); |
| 283 // right border. | 253 // right border. |
| 284 canvas->FillRect(gfx::Rect(width() - kBorderThickness, 0, kBorderThickness, | 254 canvas->FillRect(gfx::Rect(width() - kBorderThickness, 0, kBorderThickness, |
| 285 height()), | 255 height()), |
| 286 kBorderColor); | 256 kBorderColor); |
| 287 // bottom border. | 257 // bottom border. |
| 288 canvas->FillRect(gfx::Rect(0, height() - kBorderThickness, width(), | 258 canvas->FillRect(gfx::Rect(0, height() - kBorderThickness, width(), |
| 289 kBorderThickness), | 259 kBorderThickness), |
| 290 kBorderColor); | 260 kBorderColor); |
| 291 } | 261 } |
| 292 | 262 |
| 293 } // namespace ui | 263 } // namespace ui |
| OLD | NEW |